0
創建一個用於測試我的服務的ui應用程序。 UI與FooServiceUI有關係。 FooServiceUI通過使用feign客戶端向BarServiceAccessor發送請求(具有作爲fooserviceui接口的實現)。但假客戶返回這樣的迴應;使用假客戶端時,彈簧服務返回內容爲空
{"datas": [PagedResource { content: [], metadata: Metadata { number: 0, total pages: 1, total elements: 3, size: 200 }, links: [] }]}
當我直接向BarService發送請求時,我可以看到所有這些數據。
FooService getAll方法;
@RequestMapping(method = RequestMethod.GET, path = "/api/datas/")
public ResponseEntity<String> getAllDatas()
{
PagedResources<DataResource> responseEntity = null;
try
{
responseEntity = dataManagementAccessor.getAll(0, 200);
}
catch (Exception e)
{
LOG.error("Exception " + e.toString());
}
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body("{\"datas\": [" + responseEntity + "]}");
}
訪問器;
@FeignClient("https://datamanagement")
public interface DataManagementAccessor{
@RequestMapping(value = "/api/datas/", method = GET)
PagedResources<DataResource> getAll(@RequestParam("page") final Integer page,
@RequestParam("size") final Integer size);
}
BarService Code看起來像;
@RequestMapping(method = GET)
@ResponseStatus(OK)
@ApiOperation(value = "Get all datas")
@ApiResponses(value = {@ApiResponse(code = SC_OK, message = "OK", response = DataPageResponse.class),
@ApiResponse(code = SC_BAD_REQUEST, message = BAD_REQUEST_MESSAGE, response = String.class),
@ApiResponse(code = SC_UNAUTHORIZED, message = UNAUTHORIZED_MESSAGE, response = String.class),
@ApiResponse(code = SC_FORBIDDEN, message = FORBIDDEN_MESSAGE, response = String.class),
@ApiResponse(code = SC_NOT_FOUND, message = NOT_FOUND_MESSAGE, response = String.class)})
public PagedResources<Resource<DataResource>> getAll(@PageableDefault(sort = {"name"}) final Pageable pageable,
final PagedResourcesAssembler<DataResource> pagedAssembler)
{
final Page<DataData> allDatas = dataService.getAllDatas(pageable);
final Page<DataResource> pagedResources = allDatas.map(
d-> conversionService.convert(d, DataResource.class));
pagedResources.forEach(resource -> controllerLinkHandler.addDataResourceLink(resource));
return pagedAssembler.toResource(pagedResources);
}
我已經嘗試過春季JPA添加到客戶服務的gradle產出,也試圖改變映射根據使用流API集合,但仍然不起作用。
在使用_embedded行進行序列化時,可能某些東西無法正常工作?