【问题标题】:how to increase the Rest service timeout time in spring STSspring STS中如何增加Rest服务超时时间
【发布时间】:2017-12-10 00:42:48
【问题描述】:

我正在使用 spring STS 来开发具有嵌入式 tc 服务器的项目。我不知道是什么导致了这个问题,但我的休息服务总是超时 60 秒,即使我尝试在 @Transactional 中保持 timeout=100 并且我尝试将值放入 jpa.xml文件也。谁能告诉我如何增加超时时间?

【问题讨论】:

  • 你是说需要为内嵌tomcat服务器的STS增加服务器超时时间?
  • 哈哈,是的 pradeep
  • 服务超时?那它一定是客户端上的read time out?或者您的JPA 查询是否在 60 秒后超时,但您仍然希望您的客户等待结果?
  • 是的 Zilvinas ,JPA 查询在 60 秒时超时,即使我没有提到它
  • 您好 Dhari,希望我的回答对您有所帮助。如果是,请接受答案,如果不是,请告诉我,以便我即兴发挥帮助您提供更好的解决方案。

标签: spring hibernate rest spring-boot service


【解决方案1】:

你好,达利,

请双击嵌入式tomcat服务器。您可以根据需要修改超时秒数。请查看提供的屏幕截图。

More over your question is not related to increase the service timeout instead it should be server timeout which was pretty fishy to understand.Kindly update your question as suggested.

【讨论】:

  • 感谢您的回答 pradeep。我认为可能有任何关系 bw 服务器超时和休息服务超时,但不是。现在我的问题是,每当我调用我的休息服务时,它总是在 60 秒时超时,即使我将 timeout=100 保持在班级的顶部,你能告诉我该怎么做
【解决方案2】:

如果您使用的是 RestTemplate,那么您应该使用以下代码来实现超时

@Bean
public RestTemplate restTemplate() {
    return new RestTemplate(clientHttpRequestFactory());
}

private ClientHttpRequestFactory clientHttpRequestFactory() {
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    factory.setReadTimeout(2000);
    factory.setConnectTimeout(2000);
    return factory;
}}
The x

ml 配置

<bean class="org.springframework.web.client.RestTemplate">
<constructor-arg>
    <bean class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"
        p:readTimeout="2000"
        p:connectTimeout="2000" />
</constructor-arg>

参考: Spring Boot REST API - request timeout?

Timeout webservice call from client side

【讨论】:

    猜你喜欢
    • 2011-11-08
    • 2013-01-07
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-12
    • 2023-02-22
    • 1970-01-01
    相关资源
    最近更新 更多