执行顺序AuthorizationServerConfigurerAdapter->WebSecurityConfigurerAdapter导致AuthenticationManager依赖注入空指针(oauth2)

oauth2的依赖版本:

<dependency>  
       <groupId>org.springframework.security.oauth.boot</groupId>
       <artifactId>spring-security-oauth2-autoconfigure</artifactId>
       <version>2.1.2.RELEASE</version>
</dependency>

  单独在启动引导类上import,指定加载顺序

@SpringBootApplication
@Import({WebSecurityConfigurer.class, AuthorizationServerConfigurer.class})
public class SpringBootApplication {

    public static void main(String[] args) throws UnknownHostException {
         SpringApplication.run(SpringBootSecurityOauth2AuthApplication.class, args);
}


对应的认证服务器
//@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfigurer extends AuthorizationServerConfigurerAdapter {
...
}

//@Configuration
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }
...
}

  

执行顺序AuthorizationServerConfigurerAdapter->WebSecurityConfigurerAdapter导致AuthenticationManager依赖注入空指针(oauth2)

上一篇:Python模拟客户端


下一篇:spring mvc 文件上传报“由于没有提供multi-part配置,无法处理parts