SpringBoot设置接口超时时间的方法

2023-10-26,

小编给大家分享一下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();
	}
}

看完了这篇文章,相信你对SpringBoot设置接口超时时间的方法有了一定的了解,想了解更多相关知识,欢迎关注本站行业资讯频道,感谢各位的阅读!

《SpringBoot设置接口超时时间的方法.doc》

下载本文的Word格式文档,以方便收藏与打印。