我正在我的项目中实施Spring Security
在我的DAO类中,我正在定义loadUserByUsername
我的课就像
UserDAOImpl.java
@Repository public class UserDAOImpl { public UserDetails loadUserByUsername(String name)throws UsernameNotFoundException { //implementation } }
在Spring-security.xml中
<authentication-manager> <authentication-provider user-service-ref="UserDAOImpl"> </authentication-provider> </authentication-manager>
但是当我运行程序时出现错误
Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'UserDAOImpl' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'UserDAOImpl' is defined
谁能帮我解决这个问题?
通常,被组件扫描的Bean以小写字母开头,并以驼峰大小写,因此该Bean在应用程序上下文中将以userDAOImpl(not UserDAOImpl)的形式存在。
userDAOImpl
UserDAOImpl
将您的spring-security.xml代码段更改为
spring-security.xml
<authentication-manager> <authentication-provider user-service-ref="userDAOImpl"> </authentication-provider> </authentication-manager>
希望这对您有用。