Spring security empty dependency bean on UserDetailsService own implementation
I develop app consiting of Spring, Wicket, Hibernate and Spring Security. Everything works OK, but now I added own implementation of UserDetailsService to fetch users from database. I configured it in applicationContext-security.xml file and added dependency to my UserDAO using Spring. However, I got null-pointer exception because of my userDAO being null. Why is this dependency not working? I do this the very same way in, for example, WebPages subclasses and everything works well.
@Service
public class ComicsUserDetailsService implements
org.springframework.security.core.userdetails.UserDetailsService {
@SpringBean
private UserDAO userDAO;
public ComicsUserDetailsService() {
System.out.println("$$$ UserDetailsService created");
}
@Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
(bla bla)
}
}
UserDAO is quite simple class
@Service
public class UserDAO {
public UserDAO() {
System.out.println("$$$ UserDAO created");
}
@PersistenceContext
private EntityManager em;
(fetch and other 开发者_开发问答bla bla methods)
}
Well, enlightenment always come a minute too late. Simple, @SpringBean annotation is wicket-specific. Hence, in SpringSecurity is not wicket-dependent so just replacing it with @Autowired do the magic.
精彩评论