Доброго дня всем! Некоторое время мучаюсь с проблемой, никак не могу ее решить. Судя по всему не хочет @Autowired работать, однако, я даже уже не могу представить по какой причине, буду очень признателен за любую помощь:
UserDaoImplimport com.springapp.mvc.Entities.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.Iterator;
import java.util.List;
@Repository
public class UserDaoImpl implements UserDao {
/* UserEntity userEntity;*/
@PersistenceContext
private EntityManager entityManager;
public UserEntity findById(int id) {
return entityManager.find(UserEntity.class, id);
}
public UserEntity findBySSO(String sso) {
System.out.println("And here!");
/*
Query query = entityManager.createQuery("from UserEntity u where u.sso_id=:sso");
query.setParameter("sso", sso);
List<UserEntity> list = query.getResultList();
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
System.out.println("And depeeeee!");
System.out.println(iterator.next());
userEntity=(UserEntity)iterator.next();*/
return null ;
}
public EntityManager getEntityManager() {
return entityManager;
}
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
}
UserServiceImplimport com.springapp.mvc.DAO.UserDaoImpl;
import com.springapp.mvc.Entities.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Service
public class UserServiceImpl implements UserService{
@Autowired
private UserDaoImpl userDaoImpl;
@Transactional(propagation = Propagation.REQUIRED)
public UserEntity findById(int id) {
return userDaoImpl.findById(id);
}
@Transactional(propagation = Propagation.REQUIRED)
public UserEntity findBySso(String sso) {
return userDaoImpl.findBySSO(sso);
}
public UserDaoImpl getDao() {
return userDaoImpl;
}
public void setDao(UserDaoImpl dao) {
this.userDaoImpl = dao;
}
}
UserDetailServiceImplpackage com.springapp.mvc.Config.CustomSecure;
import java.util.ArrayList;
import java.util.List;
import com.springapp.mvc.Entities.UserEntity;
import com.springapp.mvc.Entities.UserRoles;
import com.springapp.mvc.Service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@Service
public class UserDetailServiceImpl implements UserDetailsService {
@Autowired
private UserServiceImpl service;
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UserEntity user = service.findBySso(username);
if (user == null)
throw new UsernameNotFoundException("user name not found");
return buildUserFromUserEntity(user);
}
private User buildUserFromUserEntity(UserEntity user) {
String username = user.getSsoId();
String password = user.getPassword();
boolean enabled = true;
boolean accountNonExpired = true;
boolean credentialsNonExpired = true;
boolean accountNonLocked = true;
UserRoles role=user.getRole();
List<UserRoles> roles = new ArrayList<UserRoles>();
roles.add(role);
User springUser = new User(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked,roles );
return springUser;
}
public UserServiceImpl getService() {
return service;
}
public void setService(UserServiceImpl service) {
this.service = service;
}
}
Ошибки28-Feb-2016 13:18:59.089 WARNING [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.support.AnnotationConfigWebApplicationContext.refresh Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.springapp.mvc.Service.UserServiceImpl com.springapp.mvc.Config.CustomSecure.UserDetailServiceImpl.service; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.springapp.mvc.DAO.UserDaoImpl com.springapp.mvc.Service.UserServiceImpl.userDaoImpl; nested exception is java.lang.IllegalArgumentException: Can not set com.springapp.mvc.DAO.UserDaoImpl field com.springapp.mvc.Service.UserServiceImpl.userDaoImpl to com.sun.proxy.$Proxy37
28-Feb-2016 13:18:59.093 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.destroy Closing JPA EntityManagerFactory for persistence unit 'default'
28-Feb-2016 13:18:59.096 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.springapp.mvc.Service.UserServiceImpl com.springapp.mvc.Config.CustomSecure.UserDetailServiceImpl.service; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.springapp.mvc.DAO.UserDaoImpl com.springapp.mvc.Service.UserServiceImpl.userDaoImpl; nested exception is java.lang.IllegalArgumentException: Can not set com.springapp.mvc.DAO.UserDaoImpl field com.springapp.mvc.Service.UserServiceImpl.userDaoImpl to com.sun.proxy.$Proxy37
Весь стек ошибок не могу скинуть,т.к пост не позволяет, но это как я понимаю, основные, с чего все началось . В конфигурации проекта сканирование адекватно настроено @ComponentScan("com.springapp.mvc").