[英]Spring security : Expecting to only find a single bean for type interface org.springframework.security.authentication.AuthenticationManager
I am having below code in Myconfig
class which extends WebSecurityConfigurerAdapter
. 我在
Myconfig
类中有以下代码,该代码扩展了WebSecurityConfigurerAdapter
。
I am getting statcktrace as Caused by: 我收到statcktrace的原因:
java.lang.IllegalArgumentException: Expecting to only find a single bean for type interfacorg.springframework.security.authentication.AuthenticationManager, but found [authenticationManagerBean, providerManager].
java.lang.IllegalArgumentException:期望仅找到类型为interfacorg.springframework.security.authentication.AuthenticationManager的单个bean,但是找到了[authenticationManagerBean,providerManager]。
@Bean(name="preAuthFilter")
public SSOCookieFilter preAuthFilter() throws Exception {
SSOCookieFilter cookieFilter= new SSOCookieFilter();
cookieFilter.setAuthenticationManager(authenticationManagerBean());
return cookieFilter;
}
@Bean(name = "preAuthProvider")
public PreAuthenticatedAuthenticationProvider getPreAuthProvider() {
PreAuthenticatedAuthenticationProvider preAuthenticatedAuthenticationProvider = new PreAuthenticatedAuthenticationProvider();
preAuthenticatedAuthenticationProvider.setPreAuthenticatedUserDetailsService(new PreAuthenticatedGrantedAuthoritiesUserDetailsService());
return preAuthenticatedAuthenticationProvider;
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
I have already tried few links from stackoverflow which suggested to have @qualifier but my bad it doesn't work(logically it should work as method name is considered as bean id). 我已经尝试了来自stackoverflow的一些链接,这些链接建议使用@qualifier,但是我不好的是它不起作用(从逻辑上讲,它应该以方法名称作为bean id起作用)。
Please help. 请帮忙。
Thanks in advance 提前致谢
The exception message indicates that a bean named providerManager
bean is instantiated by Spring. 异常消息指示Spring实例化了名为
providerManager
bean的bean。 Make sure you do not have any other AuthenticationManager
classes annotated with @Bean
or have them setup in your xml
confiuration file. 确保您没有使用
@Bean
注释的任何其他AuthenticationManager
类,或者在xml
配置文件中进行设置。
Why do you @Override
authenticationManagerBean()
? 为什么您
@Override
authenticationManagerBean()
? If this method is already annotated with @Bean
in the super class, this could be your problem. 如果此方法已经在超类中用
@Bean
注释,则可能是您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.