1

创建了一个 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 代码看起来像;

@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);
}

我已经尝试将 spring jpa 添加到客户端服务的 gradle 并且还尝试根据使用流 api 集合更改映射但仍然不起作用。

使用 _embedded 行序列化作为响应时,可能有些东西不能正常工作?

4

1 回答 1

0

@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)

我忘了在 main 方法中添加这一行。

于 2017-06-20T08:51:21.873 回答