2
我試圖將HATEOAS應用於我的彈簧引導應用程序,使用spring-hateoas
。這工作得很好,直到我包裹着我的REST調用內HystrixCommand
:如果我評論了HystrixCommand
標註出Could not find current request via RequestContextHolder
HystrixCommand註釋導致ControllerLinkBuilder中斷
:
@HystrixCommand(fallbackMethod = "myFallbackMethod")
@RequestMapping(method = RequestMethod.GET, value = "/path")
public ResponseEntity<Resources<Resource<Data>>> getAllData() {
String url = "http://localhost:8080/someotherpath"
ParameterizedTypeReference<Iterable<Data>> responseType = new ParameterizedTypeReference<Iterable<Data>>() {};
ResponseEntity<Iterable<Data>> response = restTemplate.exchange(url, HttpMethod.GET, null, responseType);
if (response.getStatusCode().is2xxSuccessful()) {
Iterable<Data> data = response.getBody();
Resources<Resource<Data>> resources = assembler.toResource(data);
return new ResponseEntity<>(resources, response.getHeaders(), response.getStatusCode());
}
return new ResponseEntity<>(response.getHeaders(), response.getStatusCode());
}
,現在包裝數據對象轉換爲資源對象我的彙編類拋出這個錯誤錯誤消失,一切正常。
我的彙編程序類僅實現Springs的ResourceAssembler<T, D>
接口並覆蓋toResource
方法。
有什麼辦法可以解決這個問題嗎?