RestTemplate基本配置类
# RestTemplateConfig
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
/**
* RestTemplate注入,配置超时时间
*/
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate getRestTemplate() {
// 配置HTTP超时时间为5s
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
httpRequestFactory.setConnectTimeout(5000);
httpRequestFactory.setReadTimeout(5000);
return new RestTemplate(httpRequestFactory);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
编辑 (opens new window)
上次更新: 2023/05/17, 22:21:48
- 01
- COLA-statemachine在多级审核业务中的实践08-25
- 02
- 单测覆盖率工具在多模块项目中的集成07-11
- 03
- Sentinel-Dashboard持久化生产环境解决方案07-05