我试图实现Feign客户端从用户的服务,我目前正在请求与oAuth2RestTemplate,它的工作原理我的用户信息。但是现在我想更改为Feign,但是我得到错误代码401可能是因为它没有携带用户令牌,所以如果Spring对Feign的支持使用了RestTemplate,我可以使用它来自定义方式我自己的豆?春天云Feign OAuth2RestTemplate
今天我实现这样
该服务的客户端
@Retryable({RestClientException.class, TimeoutException.class, InterruptedException.class})
@HystrixCommand(fallbackMethod = "getFallback")
public Promise<ResponseEntity<UserProtos.User>> get() {
logger.debug("Requiring discovery of user");
Promise<ResponseEntity<UserProtos.User>> promise = Broadcaster.<ResponseEntity<UserProtos.User>>create(reactorEnv, DISPATCHER)
.observe(Promises::success)
.observeError(Exception.class, (o, e) -> Promises.error(reactorEnv, ERROR_DISPATCHER, e))
.filter(entity -> entity.getStatusCode().is2xxSuccessful())
.next();
promise.onNext(this.client.getUserInfo());
return promise;
}
而客户端
@FeignClient("account")
public interface UserInfoClient {
@RequestMapping(value = "/uaa/user",consumes = MediaTypes.PROTOBUF,method = RequestMethod.GET)
ResponseEntity<UserProtos.User> getUserInfo();
}
感谢@戴夫,创造RequestInterceptor'的'一个bean,并从设置承载令牌o Request在RequestTemplate头上工作 – 2015-04-04 15:52:21
太棒了。也许你可以将它贡献回春季云安全? – 2015-04-05 16:58:09
当然,我会在GitHub上提出一张票,所以我们可以在那里讨论它 – 2015-04-05 20:52:07