我正在使用Spring WebClient
使用client_credentials
grant_type来对资源服务器进行呼叫
我正在使用'org.springframework.boot' version '2.1.10.RELEASE'
这些都是依赖项
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.security:spring-security-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
Am使用以下代码致电我的resource-server
,该呼叫绝对成功
@Autowired
@Qualifier("my-custom-client")
WebClient clientForMyResourceServer;
@GetMapping("/consume")
public String consumeResourceServer () {
String response = "Reply from Resource Server is : ";
String responseFromResourceServer = clientForMyResourceServer
.get()
.uri("http://localhost:8080/api/v1/hello/ping")
.retrieve()
.bodyToMono(String.class)
.block();
return response + responseFromResourceServer;
}
但是发生了什么,该客户端仅在启动时才从OAuth服务器获取Bearer-Token
,并且在已经拥有的客户端之后不获取任何新的Bearer-Token
已过期。
我得到的Bearer-Token
仅在5 minutes
有效,并且将从第6分钟起失效。因此,从第六分钟开始,我无法用此resource-server
来给我的WebClient
打电话,却无法得到401 Unauthorized
。重新启动consumer-application
请帮助