【发布时间】:2019-05-23 23:29:34
【问题描述】:
我正在尝试使用 spring boot 2.1.1 和 spring sec 5 作为 OAuth2 资源服务器的演示项目,但是当我尝试运行以下命令时
环境
- Spring Boot 2.1.1 发布
Spring 安全核心 5.1.2
Java 8
代码
@RestController
@SpringBootApplication
// @EnableResourceServer
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@GetMapping("/hello")
public String sayHello() {
return "Hello World";
}
@Configuration
static class MyWebSecurityConfigurerAdapter extends
WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests().anyRequest().authenticated()
.and()
.oauth2ResourceServer().jwt(); // <--- throws error
}
}
}
哪个会引发错误
工厂方法“springSecurityFilterChain”抛出异常;嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/security/oauth2/server/resource/web/access/BearerTokenAccessDeniedHandler
构建
我的依赖看起来像
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-security')
implementation(group: 'org.springframework.security.oauth.boot', name: 'spring-security-oauth2-autoconfigure', version: '2.1.1.RELEASE')
implementation(group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.3.4.RELEASE')
}
【问题讨论】:
标签: java spring spring-boot spring-security spring-security-oauth2