我有这样的课:
@Service("userDetailsService")
public class MyUserDetailsService implements UserDetailsService {
...
并尝试做:
<authentication-manager>
<authentication-provider user-service-ref="userDetailsService">
</authentication-provider>
</authentication-manager>
我有跟随错误:
设置时无法解析对bean'userDetailsService'的引用
bean属性'userDetailsService';嵌套异常为
org.springframework.beans.factory.NoSuchBeanDefinitionException:否
定义了名为“ userDetailsService”的bean
真的有必要声明bean吗?在这种情况下:
<beans:bean id="myUserDetailsService" class="my.package.services.MyUserDetailsService" />
编辑
这是我的
security.xml
文件:<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<http>
<form-login login-page="/login/"
authentication-failure-url="/fail/" />
<logout logout-success-url="/" />
</http>
<context:annotation-config />
<context:component-scan base-package="my.package" />
<authentication-manager>
<authentication-provider user-service-ref="myUserDetailsService">
<!-- <password-encoder hash="md5" /> -->
</authentication-provider>
</authentication-manager>
</beans:beans>
原因:
匹配的通配符是严格的,但找不到用于的声明
元素“ context:annotation-config”。
最佳答案
您缺少上下文的架构位置。
因此,您的xml应该以:
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">