我一直收到一条消息:“org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为’userDetailsService’的bean”,即使bean被定义为UserDetailsServiceImpl类中的服务.如:
@Service(value="userDetailsService")
public class UserDetailsServiceImpl implements UserDetailsService{
我正在使用最新的Spring和Spring Security.
我不确定我做错了什么.我正在粘贴我的spring xml文件的配置. spring-security.xml显示它在使用组件扫描时可以从servlet-context.xml中找到bean.
谢谢
org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.filterChains': Cannot resolve reference to bean org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean org.springframework.security.authentication.ProviderManager#0' while setting bean property authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerfactorybean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.config.authentication.AuthenticationManagerfactorybean#0': factorybean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.authenticationManager': Cannot resolve reference to bean org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailsService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailsService' is defined
弹簧security.xml文件
logout controls -->
Failed" />
<logout invalidate-session="true" logout-success-url="/"
delete-cookies="JSESSIONID" />
servlet的context.xml中
MysqL.jdbc.Driver"/>
MysqL://localhost:3306/dbName"/>
factorybean">
MysqL5Dialectsql">truesql">true
最佳答案
您需要在其他Spring配置文件中放置组件扫描,而不仅仅是servlet配置.
原文链接:https://www.f2er.com/spring/431638.html它们是不同的上下文,一个由上下文加载器侦听器加载,一个由调度程序servlet加载.