我正在尝试通过设置application.yml
的{{1}}中的密钥来配置具有JWT验证程序密钥的Spring OAuth2资源服务器应用程序,如here所述。但是spring.oauth2.resource.jwt.key-value
似乎无法识别它,从而导致spring-security-oauth2-autoconfigure
的响应。
我已经调试了OAuth2过滤器类,并且可以识别出未检测到验证者密钥。
401 UNAUTHORIZED
build.gradle
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-snAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.2.0.RELEASE'
implementation 'org.springframework.security:spring-security-jwt:1.0.11.RELEASE'
}
DemoApplication.java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableResourceServer
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class,args);
}
@GetMapping(path = "/hello")
public String sayHello() {
return "hello";
}
}
application.yml
我的设置中是否存在明显的错误?缺少依赖项?春季版本错误?我在这里真的看不到任何进展。期待您的回答!