[英]SpringBoot: Timeout Rest API request when no response is returned
I need to timeout my Rest Api when no response is returned.当没有返回响应时,我需要让我的 Rest Api 超时。 For example, when I make a request and if it takes more than 10 seconds to return a response, then Timeout.
例如,当我发出请求时,如果返回响应的时间超过 10 秒,则超时。
The below code works fine, but is there a minimal solution for this, rather than wrapping all the controller methods within the Callable<>?下面的代码可以正常工作,但是是否有一个最小的解决方案,而不是在 Callable<> 中包装所有 controller 方法?
If NO, Is there a way in which I can wrap all the controller methods inside Callable<> GLOBALLY rather than doing it to each METHOD?如果否,有没有一种方法可以将所有 controller 方法包装在 Callable<> GLOBALLY 中,而不是对每个方法都这样做?
Rest Controller Rest Controller
@GetMapping("/getData)"
public Callable<String> getData() throws Exception {
return new Callable<String>() {
@Override
public String call() throws Exception {
}
}
}
application.properties应用程序属性
spring.mvc.async.request-timeout=10000
There are many ways to achieve this use case.有很多方法可以实现这个用例。
I think below link will help you to implement timeout based on your requirement我认为下面的链接将帮助您根据您的要求实施超时
https://www.baeldung.com/spring-rest-timeout https://www.baeldung.com/spring-rest-timeout
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.