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(); } ... }