springboot如何设置接口的响应时间
两张方法
1、在配置文件
application.properties中或者application.yml加上spring.mvc.async.request-timeout=30000,意思是设置超时时间为30000ms即30s
spring.mvc.async.request-timeout=30000
spring:
mvc:
async:
request-timeout: 30000
2、在config配置类里配置
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureAsyncSupport(final AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(30000);
configurer.registerCallableInterceptors(timeoutInterceptor());
}
@Bean
public TimeoutCallableProcessingInterceptor timeoutInterceptor() {
return new TimeoutCallableProcessingInterceptor();
}
}
本文介绍了两种在SpringBoot中设置接口响应时间的方法:一种是在配置文件中直接配置,另一种是在配置类中进行设置。通过这两种方式可以有效地控制接口请求的超时时间。
4140

被折叠的 条评论
为什么被折叠?



