SpringBoot設(shè)置接口超時時間的方法
SpringBoot設(shè)置接口訪問超時時間有兩種方式
一、在配置文件application.properties中加了spring.mvc.async.request-timeout=20000,意思是設(shè)置超時時間為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 設(shè)置超時時間
項目有一對外開放api,外網(wǎng)訪問經(jīng)常出現(xiàn)超時,剛接觸spring boot不久,內(nèi)置的tomcat不像原先那樣在server.xml中設(shè)置request超時時間。
后來查了些資料,在配置文件application.properties中加了spring.mvc.async.request-timeout=20000,意思是設(shè)置超時時間為20000ms即20s,超時問題的確不怎么發(fā)生了。
還有另外一種設(shè)置方式,如下:
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(); } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Spring?Boot實現(xiàn)配置文件的自動加載和刷新功能
這篇文章我們介紹了Spring?Boot如何實現(xiàn)配置文件的自動加載和刷新,本文結(jié)合實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2023-05-05Java實現(xiàn)的權(quán)重算法(按權(quán)重展現(xiàn)廣告)
這篇文章主要介紹了Java實現(xiàn)的權(quán)重算法(按權(quán)重展現(xiàn)廣告),本文講解了算法實現(xiàn)原理和實現(xiàn)代碼,需要的朋友可以參考下2015-04-04RestTemplate對HttpClient的適配源碼解讀
這篇文章主要為大家介紹了RestTemplate對HttpClient的適配源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-10-10基于idea操作hbase數(shù)據(jù)庫并映射到hive表
這篇文章主要介紹了用idea操作hbase數(shù)據(jù)庫,并映射到hive,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03