我有这样的课:
@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-22 18:49:34
您缺少上下文的架构位置。
因此,您的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">发布于 2011-11-17 19:27:44
如果使用注释来指定bean,则需要在配置中为它们添加一个条目到扫描类路径。
<context:component-scan base-package="org.example"/>发布于 2011-11-17 19:26:12
@Service扩展了允许classpath scanning的@Component。
您可以同时启用classpath scanning和annotations
<context:annotation-config />
<context:component-scan base-package="com.package.a,com.b" />我不知道你用的是什么版本。尝尝这个。
<authentication-manager>
<authentication-provider user-service-ref="userDetailsService">
<!-- <password-encoder hash="md5" /> -->
</authentication-provider>
</authentication-manager>除非您像提供名称一样提供名称,否则它将是类名。但是您提供了相同的名称,但在配置文件中声明了另一个名称。
如果你没有名字的@Service,那就没问题了。
https://stackoverflow.com/questions/8173009
复制相似问题