gpt4 book ai didi

java - 没有名为 authenticationManager 的 bean

转载 作者:IT老高 更新时间:2023-10-28 13:48:48 26 4
gpt4 key购买 nike

Possible Duplicate:
Getting error org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘springSecurityFilterChain’ is defined

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

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.

最佳答案

authenticationManager 是按名称查找的,所以只需将其更改为以下内容:

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

关于java - 没有名为 authenticationManager 的 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14071759/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com