SpringBoot设置接口超时时间的方法
SpringBoot设置接口访问超时时间有两种方式
一、在配置文件application.properties中加了spring.mvc.async.request-timeout=20000,意思是设置超时时间为20000ms即20s,
二、还有一种就是在config配置类中加入:
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureAsyncSupport(final AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(20000);
configurer.registerCallableInterceptors(timeoutInterceptor());
}
@Bean
public TimeoutCallableProcessingInterceptor timeoutInterceptor() {
return new TimeoutCallableProcessingInterceptor();
}
}
PS:SpringBoot Rest Api 设置超时时间
项目有一对外开放api,外网访问经常出现超时,刚接触spring boot不久,内置的tomcat不像原先那样在server.xml中设置request超时时间。
后来查了些资料,在配置文件application.properties中加了spring.mvc.async.request-timeout=20000,意思是设置超时时间为20000ms即20s,超时问题的确不怎么发生了。
还有另外一种设置方式,如下:
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureAsyncSupport(final AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(20000);
configurer.registerCallableInterceptors(timeoutInterceptor());
}
@Bean
public TimeoutCallableProcessingInterceptor timeoutInterceptor() {
return new TimeoutCallableProcessingInterceptor();
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
springboot使用之多个filter的执行顺序以及配置方式
这篇文章主要介绍了springboot使用之多个filter的执行顺序以及配置方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2021-08-08
使用XSD校验Mybatis的SqlMapper配置文件的方法(1)
这篇文章以前面对SqlSessionFactoryBean的重构为基础,简单的介绍了相关操作知识,然后在给大家分享使用XSD校验Mybatis的SqlMapper配置文件的方法,感兴趣的朋友参考下吧2016-11-11
Spring boot如何通过@Scheduled实现定时任务及多线程配置
这篇文章主要介绍了Spring boot如何通过@Scheduled实现定时任务及多线程配置,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2019-12-12
java Iterator接口和LIstIterator接口分析
这篇文章主要介绍了java Iterator接口和LIstIterator接口分析的相关资料,需要的朋友可以参考下2017-05-05


最新评论