未释放Spring引导REST终结点连接

未释放Spring引导REST终结点连接,rest,spring-boot,Rest,Spring Boot,我创建了SpringBoot(2.1.4.RELEASE)REST端点以从服务器获取一些数据。当我从浏览器调用这个端点时,我在浏览器窗口中看到JSON,但我注意到fav中的微调器图标持续60秒。当我查看网络选项卡时,我从未看到请求的响应部分。60秒后,它说它失败了。当我在调试器中浏览代码时,我看到数据正在从控制器返回,而当我“播放”堆栈的其余部分时,一切都完成了(分配给服务请求的线程),我有点困惑是什么导致了这种行为 @GetMapping(path="/recipes") public Res

我创建了SpringBoot(2.1.4.RELEASE)REST端点以从服务器获取一些数据。当我从浏览器调用这个端点时,我在浏览器窗口中看到JSON,但我注意到fav中的微调器图标持续60秒。当我查看网络选项卡时,我从未看到请求的响应部分。60秒后,它说它失败了。当我在调试器中浏览代码时,我看到数据正在从控制器返回,而当我“播放”堆栈的其余部分时,一切都完成了(分配给服务请求的线程),我有点困惑是什么导致了这种行为

@GetMapping(path="/recipes")
public ResponseEntity<Collection<HpManifest>> getRecipes() {
    ResponseEntity<Collection<HpManifest>> response = hpService.getRecipes();
    return response;
}

public ResponseEntity<Collection<HpManifest>> getRecipes() {
    logger.info("Retrieving recipes from");

    UriComponentsBuilder builder = 
            UriComponentsBuilder.fromHttpUrl(endpointManifests)
                .queryParam("type", HpManifestType.RECIPE.getType());

    logger.info("REST endpoint: " + builder.toUriString());

    ResponseEntity<Collection<HpManifest>> recipes = restTemplate.exchange(
            builder.toUriString(), 
            HttpMethod.GET, null, new ParameterizedTypeReference<Collection<HpManifest>>() {});

    logger.info("recipes are:");
    recipes.getBody().forEach(r -> logger.info(r.toString()));

    return recipes;
}
@GetMapping(path=“/recipes”)
公共响应getRecipes(){
ResponseEntity response=hpService.getRecipes();
返回响应;
}
公共响应getRecipes(){
logger.info(“从中检索配方”);
UriComponentsBuilder生成器=
UriComponentsBuilder.fromHttpUrl(端点清单)
.queryParam(“类型”,HpManifestType.RECIPE.getType());
info(“REST端点:+builder.toUriString());
ResponseEntity recipes=restTemplate.exchange(
builder.string(),
HttpMethod.GET,null,新的ParameteredTypeReference(){});
logger.info(“食谱是:”);
recipes.getBody().forEach(r->logger.info(r.toString());
返回食谱;
}

前几天我遇到了类似的问题。在我的例子中,
recipes
(从
restemplate.exchange
方法返回)在标题中包含一个
传输编码:chunked
,然后当您返回
recipes
时,您的spring框架可能还包含一个
内容长度
标题。在对浏览器的响应中,这两个标题的组合可能会导致问题,因为浏览器认为它正在收回分块数据,但实际上并非如此。我建议从您的
配方
变量中创建一个新的
响应
,如下所示:

return ResponseEntity.status(recipes.getStatusCode()).body(response.getBody());

或者,您可以强制spring框架返回分块数据,但我认为这不是正确的方法。

谢谢。我试图返回一个新的响应实体,但没有看到您的响应。但根据你的解释,它为什么也会这样做是有道理的。再次感谢。