我有这样的课:
@Service("userDetailsService")
public class MyUserDetailsService implements UserDetailsService {
...并试图做到:
<authentication-manager>
<authentication-provider user-service-ref="userDetailsService">
</authentication-provider>
</authentication-manager>我发现了一些错误:
在设置bean属性'userDetailsService‘时不能解析对bean 'userDetailsService’的引用;嵌套异常为userDetailsService没有定义名为‘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:注释-config’找到任何声明。
发布于 2011-11-17 19:27:44
如果使用注释来指定bean,则需要在配置中为它们添加一个条目到扫描类路径。
<context:component-scan base-package="org.example"/>https://stackoverflow.com/questions/8173009
复制相似问题