我正在开发一个由OAuth2提供程序保护的spring应用程序(客户端)。该应用程序应该对另一个spring应用程序(资源服务器)进行一些REST调用。为了执行REST调用,我将使用spring的WebClient。
因此,我尝试创建一个WebClient类型的bean,可以在几个博客中找到它。
@Configuration
public class AppConfig {
@Bean
public WebClient webClient(ReactiveClientRegistrationRepository clientRegistrations) {
ServerOAuth2AuthorizedClientExchangeFilterFunction oauth =
new ServerOAuth2AuthorizedClientExchangeFilterFunction(clientRegistrations,
new UnAuthenticatedServerOAuth2AuthorizedClientRepository());
oauth.setDefaultClientRegistrationId("myprovider");
return WebClient.builder().filter(oauth).build();
}
}
启动应用程序时,出现以下错误:
The following candidates were found but could not be injected:
- Bean method 'clientRegistrationRepository' in 'ReactiveOAuth2ClientAutoConfiguration' not loaded because NoneNestedConditions 1 matched 0 did not; NestedCondition on ReactiveOAuth2ClientAutoConfiguration.NonServletApplicationCondition.ServletApplicationCondition found 'session' scope
Action:
Consider revisiting the entries above or defining a bean of type 'org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository' in your configuration.
当使用OAuth2身份验证时,有几个网站完全推荐此代码来生成WebClient实例,我想知道自己做错了什么吗?
您对我有什么建议吗?
谢谢。
答案 0 :(得分:0)