Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用外部客户端时,Spring服务返回内容为空_Java_Spring_Feign - Fatal编程技术网

Java 使用外部客户端时,Spring服务返回内容为空

Java 使用外部客户端时,Spring服务返回内容为空,java,spring,feign,Java,Spring,Feign,创建了一个ui应用程序来测试我的服务。UI与FooServiceUI有关系。FooServiceUI使用外部客户端将请求发送到BarServiceAccessor(在FooServiceUI上实现为接口)。但假客户的回复是这样的 {"datas": [PagedResource { content: [], metadata: Metadata { number: 0, total pages: 1, total elements: 3, size: 200 }, links: [] }]}

创建了一个ui应用程序来测试我的服务。UI与FooServiceUI有关系。FooServiceUI使用外部客户端将请求发送到BarServiceAccessor(在FooServiceUI上实现为接口)。但假客户的回复是这样的

{"datas": [PagedResource { content: [], metadata: Metadata { number: 0, total pages: 1, total elements: 3, size: 200 }, links: [] }]}
当我直接向BarService发送请求时,我可以看到所有这些数据

fooservicegetall方法

@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 + "]}");
}
@RequestMapping(method=RequestMethod.GET,path=“/api/datas/”)
公共响应getAllDatas()
{
PagedResources responseEntity=null;
尝试
{
responseEntity=dataManagementAccessor.getAll(0200);
}
捕获(例外e)
{
LOG.error(“异常”+e.toString());
}
返回ResponseEntity.ok()
.header(HttpHeaders.CONTENT\u TYPE、MediaType.APPLICATION\u JSON\u值)
.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);
}
@FeignClient(“https://datamanagement")
公共接口数据管理访问器{
@RequestMapping(value=“/api/datas/”,method=GET)
PagedResources getAll(@RequestParam(“页面”)最终整数页面,
@RequestParam(“大小”)最终整数大小);
}
条形码服务代码看起来像

@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);
}
@RequestMapping(方法=GET)
@响应状态(OK)
@ApiOperation(value=“获取所有数据”)
@ApiResponses(值={@ApiResponse(code=SC_OK,message=“OK”,response=DataPageResponse.class),
@ApiResponse(代码=SC\u坏请求,消息=BAD\u请求,消息,响应=String.class),
@ApiResponse(代码=SC\u UNAUTHORIZED,消息=UNAUTHORIZED\u message,响应=String.class),
@ApiResponse(代码=SC\u禁止,消息=禁止消息,响应=String.class),
@ApiResponse(code=SC\u NOT\u FOUND,message=NOT\u FOUND\u message,response=String.class)})
public PagedResources getAll(@PageableDefault(sort={“name”})最终可分页,
最终页面数据源汇编页面(汇编)
{
最终页面allDatas=dataService.getAllDatas(可分页);
最后一页pagedResources=allDatas.map(
d->conversionService.convert(d,DataResource.class));
pagedResources.forEach(resource->controllerLinkHandler.addDataResourceLink(resource));
返回pagedAssembler.toResource(pagedResources);
}
我已经尝试将SpringJPA添加到客户端服务的gradle中,并尝试根据UseStreamAPI集合更改映射,但仍然不起作用

可能是在使用_嵌入式行进行串行化以响应时出现了一些问题?

@EnableHypermediaSupport(type=EnableHypermediaSupport.HypermediaType.HAL)

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