所以我有一个用户详细信息的课程
@Service("customUserDetailsService")
public class TimexUserDetailsService implements UserDetailsService {
@Autowired private UserService userService;
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
TimexUser user = userService.getUserByUsername(username);
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
for (String authority : user.getAuthorities())
authorities.add(new GrantedAuthorityImpl(authority));
return new User(username, user.getPassword(), true, true, true, true, authorities);
}
}
和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: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/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">
<http use-expressions="true">
<intercept-url pattern="/home" access="permitAll" />
<intercept-url pattern="/projects/**" access="isAuthenticated()" />
<intercept-url pattern="/projects/add/**" access="hasRole('manager')" />
<form-login />
</http>
<context:annotation-config />
<context:component-scan base-package="com.yonder.timex" />
<authentication-manager>
<authentication-provider ref="customUserDetailsService" />
</authentication-manager>
</beans:beans>
我收到了错误
SEVERE:将上下文初始化事件发送给侦听器的异常 类的实例 org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException:错误 用名字创建bean &#39; org.springframework.security.authentication.ProviderManager#0&#39 ;: 无法创建内豆&#39;(内豆)&#39;类型 [org.springframework.security.config.authentication.AuthenticationManagerFactoryBean] 同时设置bean属性&#39; parent&#39 ;;嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 用名称&#39;(内部bean)&#39;创建bean:FactoryBean引发了异常 对象创建;嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 用名字创建bean &#39; org.springframework.security.authenticationManager&#39;:无法解决 引用bean&#39; customUserDetailsService&#39;设置bean时 财产提供者&#39;用键[0];嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 使用名称&#39; customUserDetailsService创建bean&#39 ;:注入 自动连接依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 autowire字段:private com.yonder.timex.service.UserService com.yonder.timex.TimexUserDetailsService.userService;嵌套异常 是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有 找到匹配的[com.yonder.timex.service.UserService]类型的bean 依赖:预计至少有1个bean有资格成为autowire 这种依赖的候选人。依赖注释: {@ org.springframework.beans.factory.annotation.Autowired(所需=真)} 在 org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281) 在 org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:125) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 在 org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:293) 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) 在 org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282) 在 org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204) 在 org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) 在 org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205) 在 org.apache.catalina.core.StandardContext.start(StandardContext.java:4704) 在 org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) 在org.apache.catalina.core.StandardHost.start(StandardHost.java:840) 在 org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) 在 org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463) 在 org.apache.catalina.core.StandardService.start(StandardService.java:525) 在 org.apache.catalina.core.StandardServer.start(StandardServer.java:754) 在org.apache.catalina.startup.Catalina.start(Catalina.java:595)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:601)at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)at at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
基本问题是我想为我的用户详细信息服务提供身份验证提供程序,但我不能这样做。
非常感谢Tranca
答案 0 :(得分:0)
问题来自其他地方。 我没有为bean创建正确的顺序,因此这个错误