1.RestTemplate超时

设置配置HttpComponentsClientHttpRequestFactory中的RequestConfig属性

RestTemplateConfig:

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate; /**
* Created by qhong on 2018/9/10 17:53
**/
@Slf4j
@Configuration
public class RestTemplateConfig { @Bean
@ConfigurationProperties(prefix = "rest.connection")
public HttpComponentsClientHttpRequestFactory httpRequestFactory() {
return new HttpComponentsClientHttpRequestFactory();
} @Bean
public RestTemplate customRestTemplate(){
return new RestTemplate(httpRequestFactory());
}
}

application.properties:

#restTemplate配置
rest.connection.connectionRequestTimeout=30000
rest.connection.connectTimeout=30000
rest.connection.readTimeout=30000

或者:

#restTemplate配置
rest.connection.connection-request-timeout=30000
rest.connection.connect-timeout=30000
rest.connection.read-timeout=30000

上面这两种格式的配置都可以。

参考:

https://blog.csdn.net/wtopps/article/details/80990464

https://www.cnblogs.com/yangzhilong/p/6640207.html

https://www.jianshu.com/p/60174c9eb735

https://github.com/jadyer/seed/blob/master/seed-boot/src/main/java/com/jadyer/seed/boot/RestTemplateConfiguration.java


2.HttpUrlConnection超时

参考:

http://ju.outofmemory.cn/entry/23483

http://m635674608.iteye.com/blog/2265958

SpringBoot 超时设置的更多相关文章

  1. delphi tidhttp 超时设置无效的解决方法

    现在delphi都发布到xe8了,tidhttp还有缺陷,那就是超时设置在没有网络或者连不上服务器的时候是无效的,不管你设置为多少都要10-20秒.connectTimeout和readTimeout ...

  2. Linux串口中的超时设置

    在Linux下使用串口通信时,默认的阻塞模式是不实用的.而采用select或epoll机制的非阻塞模式,写代码有比较麻烦.幸好Linux的串口自己就带有超时机制. Linux下使用termios.h中 ...

  3. org.apache.http.client.HttpClient; HttpClient 4.3超时设置

    可用的code import org.apache.commons.lang.StringUtils;import org.apache.http.HttpEntity;import org.apac ...

  4. HttpClient 3.X 4.3 4.x超时设置

    HttpClient 4.3.HttpClient这货和Lucene一样,每个版本的API都变化很大,这有点让人头疼.就好比创建一个HttpClient对象吧,每一个版本的都不一样, 3.X是这样的 ...

  5. Apache性能优化、超时设置,linux 重启apache

    在httpd.conf中去掉Include conf/extra/httpd-default.conf前的#以使httpd-default.php生效.其中调节以下参数Timeout 15 (连接超时 ...

  6. libcurl多线程超时设置不安全(转)

    from http://www.cnblogs.com/kex1n/p/4135263.html (1), 超时(timeout) libcurl 是 一个很不错的库,支持http,ftp等很多的协议 ...

  7. CXF超时设置

    转自: http://peak.iteye.com/blog/1285211 http://win.sy.blog.163.com/blog/static/9419718620131014385644 ...

  8. 使用select io复用实现超时设置

    在linux的socket编程中,经常会遇到超时设置的问题,例如请求方如果在Ks内不发送数据则服务器要断开连接停止服务.这里我使用select的io复用实现超时5s设置,具体代码片段如下: fd_se ...

  9. jquery ajax超时设置

    var ajaxTimeoutTest = $.ajax({ url:'',  //请求的URL timeout : 1000, //超时时间设置,单位毫秒 type : 'get',  //请求方式 ...

随机推荐

  1. 20180309 - C# demo - 1

    using System; namespace HelloWorldApplication { class HelloWorld { static void Main(string[] args) { ...

  2. 80x86的内存寻址机制

    80x86的内存寻址机制 80386处理器的工作模式: 模式. 模式之间可以相互转换,而模式之间不可以相互转换. DOS系统运行于实模式下,Windows系统运行与保护模式下. 实模式: 80386处 ...

  3. c++ string split

    #include <iterator> #include <regex> std::vector<std::string> s_split(const std::s ...

  4. tcp/ip 3次握手和4次挥手

    tcp/ip 3次握手和4次挥手

  5. Spring NoSuchBeanDefinitionException

    转http://www.baeldung.com/spring-nosuchbeandefinitionexception 1. Overview In this article, we are di ...

  6. SQL优化(转)

    1. 负向条件查询不能使用索引 select * from order where status!=0 and stauts!=1 not in/not exists都不是好习惯 可以优化为in查询: ...

  7. JustOj 1936: 小明A+B

    题目描述 小明今年3岁了, 现在他已经能够认识100以内的非负整数, 并且能够进行100以内的非负整数的加法计算. 对于大于等于100的整数, 小明仅保留该数的最后两位进行计算, 如果计算结果大于等于 ...

  8. Lonsdor K518ISE free update news on what makes and year can work

    Lonsdor K518ISE engineers recently tested a number of cars and verified working great, below are tes ...

  9. 怎样从外网访问内网Redis数据库?

    本地安装了一个Redis数据库,只能在局域网内访问到,怎样从外网也能访问到本地的Redis数据库呢?本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Redis数据库 默认安装的Redis ...

  10. 新建web项目myeclipse基本设置

    1. General --> Workspace --> UTF-82. General --> Editors --> Associations --> JSP --& ...