【发布时间】:2019-02-05 12:04:38
【问题描述】:
考虑以下代码:
@RestController
@RequestMapping("/timeout")
public class TestController {
@Autowired
private TestService service;
@GetMapping("/max10secs")
public String max10secs() {
//In some cases it can take more than 10 seconds
return service.call();
}
}
@Service
public class TestService {
public String call() {
//some business logic here
return response;
}
}
我想要完成的是,如果 TestService 中的方法 call 花费超过 10 秒,我想取消它并使用 HttpStatus.REQUEST_TIMEOUT 代码生成响应。
【问题讨论】:
标签: spring spring-boot spring-restcontroller spring-async request-timed-out