本文介绍了没有名为authenticationManager的bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my Spring Application, I keep getting this error:

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文件中,我定义了以下内容:

In my Spring Security context xml file, I have defined the following:

<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>

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

Any ideas why its complaining, when I have clearly defined my authentication-manager and authentication-provider?

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

Note: this might help, its a more descriptive error:

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.


推荐答案

通过名称查找authenticationManager,所以只需更改它如下:

The authenticationManager is looked up by name, so just change it to the following:

<authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="myUserDetailsService">
        <password-encoder ref="encoder" />
    </authentication-provider>
</authentication-manager>

这篇关于没有名为authenticationManager的bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 05:25