【问题标题】:What is default rest api time out in spring boot 2.2spring boot 2.2中默认的rest api超时是什么
【发布时间】:2020-10-16 18:53:07
【问题描述】:

什么是 spring boot 2.2 中的默认 api 超时以及我如何更改它。是用于更改超时的任何属性键。 我想在 10 秒后设置超时。

【问题讨论】:

  • @Transactional 注释带有一个超时参数,您可以在其中为 RestController 中的特定方法指定超时时间(以秒为单位)

标签: spring-boot microservices rest


【解决方案1】:

通过@Transactional 注解,您可以为@RestController 中的特定方法指定超时(以秒为单位)。

@RequestMapping(value = "/method",
    method = RequestMethod.POST,
    produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
@Transactional(timeout = 120)

【讨论】:

    【解决方案2】:

    在您的 application.properties 或 application.yml 中使用设置 server.connection-timeout=10000。

    server.connection-timeout - 连接器在关闭连接之前等待另一个 HTTP 请求的时间(以毫秒为单位)。未设置时,将使用连接器的特定于容器的默认值。使用值 -1 表示没有(即无限)超时。

    【讨论】:

    • 我已经在应用中添加了server.tomcat.connection-timeout=30s,但是超时不起作用
    • 你是在tomcat上运行还是在spring boot自己的servlet容器上运行?我想上面提到的设置仅适用于 spring boot 自己的 servlet 容器
    • 您还可以看到这篇 (baeldung.com/spring-boot-configure-tomcat) 文章。这可能会有所帮助,但它们也使用相同的设置,但是它们将值设置为字符串 - 5s 持续 5 秒
    猜你喜欢
    • 1970-01-01
    • 2020-02-01
    • 2016-04-23
    • 2018-09-11
    • 1970-01-01
    • 2019-12-04
    • 2020-06-08
    • 2016-04-16
    • 2015-06-21
    相关资源
    最近更新 更多