11

可能重复:
出现错误 org.springframework.beans.factory.NoSuchBeanDefinitionException:未定义名为“springSecurityFilterChain”的 bean

在我的 Spring Application 中,我不断收到此错误:

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

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

<beans:bean id="myUserDetailsService" class="com.myProject.core.security.MyUserDetailsService" />

<beans:bean id="encoder" class="com.myProject.core.security.HmacPasswordEncoder" />

<authentication-manager id="clientAuthenticationManager" >
    <authentication-provider user-service-ref="myUserDetailsService">
        <password-encoder ref="encoder" />
    </authentication-provider>
</authentication-manager>

当我明确定义了我的身份验证管理器和身份验证提供者时,任何想法为什么会抱怨?

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

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 <authentication-manager> element to your configuration (with child
<authentication-provider> elements)? Alternatively you can use the authentication-manager-ref
attribute on your <http> and <global-method-security> elements.
4

3 回答 3

13

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

<authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="myUserDetailsService">
        <password-encoder ref="encoder" />
    </authentication-provider>
</authentication-manager>
于 2012-12-28T15:32:10.940 回答
1

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

<http use-expressions="true" authentication-manager-ref="clientAuthenticationManger">
于 2012-12-28T16:11:14.537 回答
0

看看这个链接:

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

...

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

于 2012-12-28T15:31:19.613 回答