@Qualifier没有拿起@Bean

时间:2016-10-05 23:53:30

标签: java spring spring-security spring-boot oauth-2.0

我正在尝试按照此tutorial关于在我刚刚开始使用的网络应用程序中设置OAuth身份验证,我是一个相当新的春天,并且一直在考虑为什么OAuth2AuthorisationServerConfig班不能拿起豆。

@Configuration
public class ServerSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().withUser("JL").password("TEST").roles("USER");
    }

    @Override
    @Bean //Here is the bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/", "/login", "/register").permitAll()
                .anyRequest().authenticated()
                .and().formLogin().permitAll()
                .and().logout().permitAll();
    }

}

@Configuration
public class OAuth2AuthorisationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    @Qualifier("authenticationManagerBean")  // here is the qualifier for bean
    private AuthenticationManager authenticationManager;
    ....
}

这两个类在同一个包中

1 个答案:

答案 0 :(得分:0)

在OAuth2AuthorisationServerConfig类中,我用@ComponentScan注释了它,这似乎解决了这个问题