没有名为authenticationManager的bean

可能重复:
获取错误org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为’springSecurityFilterChain’的bean

在我的Spring应用程序中,我不断收到此错误:

No bean named 'org.springframework.security.authenticationManager' is defined: Did you forget to add a gobal  element to your configuration (with child  elements)? Alternatively you can use the authentication-manager-ref attribute on your  and  elements. 

在我的Spring Security上下文xml文件中,我定义了以下内容:

        

当我明确定义了我的身份validation管理器和身份validation提供程序时,有什么想法让它抱怨吗?

注意:这可能会有所帮助,这是一个更具描述性的错误:

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#2' while setting bean property 'sourceList' with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#2': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [1]; 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.NoSuchBeanDefinitionException: No bean named 'org.springframework.security.authenticationManager' is defined: Did you forget to add a gobal  element to your configuration (with child  elements)? Alternatively you can use the authentication-manager-ref attribute on your  and  elements. 

将按名称查找authenticationManager,因此只需将其更改为以下内容:

      

您需要更改Spring Security Context文件以查找clientAuthenticationManager。 您可以将此行添加到http设置中

  

看看这个链接:

  • 获取错误org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为’springSecurityFilterChain’的bean

请注意,filter实际上是DelegatingFilterProxy,而不是实际实现filter逻辑的类。 DelegatingFilterProxy所做的是将Filter的方法委托给从Spring应用程序上下文中获取的bean。

您需要定义一个名为springSecurityFilterChain的bean,它在您的应用程序上下文中实现javax.servlet.Filter。