我正在使用 spring spring security oAuth2 客户端。还有默认的 OAuth2RestTemplate 声明,看起来像
@Bean
@Primary
public OAuth2RestTemplate oauth2RestTemplate(OAuth2ClientContext oauth2ClientContext,
OAuth2ProtectedResourceDetails details) {
OAuth2RestTemplate template = new OAuth2RestTemplate(details,
oauth2ClientContext);
return template;
}
我需要的是提供自定义错误处理,所以我试图把它放到上下文中
@Bean
public OAuth2RestTemplate restTemplate(OAuth2ClientContext oauth2ClientContext,
OAuth2ProtectedResourceDetails details) {
OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(details, oauth2Context);
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
public void handleError(ClientHttpResponse response) throws IOException {
// do some stuff
}
});
return restTemplate;
}
这里的问题是默认实现被注释为@Primary
,所以我想知道如何覆盖它?