简体   繁体   English

Spring安全性:期望只为类型接口org.springframework.security.authentication.AuthenticationManager找到一个bean。

[英]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.

相关问题 需要一个 org.springframework.security.authentication.AuthenticationManager 类型的 bean - required a bean of type org.springframework.security.authentication.AuthenticationManager *** 中的字段 authenticationManager 需要一个找不到的 &#39;org.springframework.security.authentication.AuthenticationManager&#39; 类型的 bean - Field authenticationManager in *** required a bean of type 'org.springframework.security.authentication.AuthenticationManager' that could not be found service.SecurityServiceImpl 中的字段 authenticationManager 需要类型为“org.springframework.security.authentication.AuthenticationManager”的 bean - Field authenticationManager in service.SecurityServiceImpl required a bean of type 'org.springframework.security.authentication.AuthenticationManager' 无法自动装配字段:私有 org.springframework.security.authentication.AuthenticationManager - Could not autowire field: private org.springframework.security.authentication.AuthenticationManager 没有类型为&#39;org.springframework.security.authentication.AuthenticationProvider&#39;的合格Bean - No qualifying bean of type 'org.springframework.security.authentication.AuthenticationProvider' java.lang.NoClassDefFoundError:org / springframework / security / authentication / AuthenticationManager - java.lang.NoClassDefFoundError: org/springframework/security/authentication/AuthenticationManager <spring security>找不到“org.springframework.security.oauth2.client.registration.ClientRegistrationRepository”类型的 bean</spring> - <Spring Security> bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' cannot be found spring 安全性:NoSuchBeanDefinitionException:找不到 [org.springframework.security.config.annotation.ObjectPostProcessor] 类型的合格 bean - spring security: NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.config.annotation.ObjectPostProcessor] found 找不到类型为“org.springframework.security.oauth2.client.registration.ClientRegistrationRepository”的 Bean。 - Spring 安全 - Bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' that could not be found. - Spring Security 带有xml config的Spring安全性NoSuchBeanDefenitionException否AuthenticationManager类型的合格Bean - Spring security with xml config NoSuchBeanDefenitionException No Qualifying bean of type AuthenticationManager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM