java请求url超时_spring boot2 RestTemplate 请求URL超时

spring boot2 RestTemplate 请求URL超时

RestTemplate配置代码如下

@Bean

public RestTemplate restTemplate(RestTemplateBuilder builder) {

HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();

httpRequestFactory.setConnectionRequestTimeout(30000);

httpRequestFactory.setConnectTimeout(30000);

httpRequestFactory.setReadTimeout(30000);

return builder.requestFactory(() -> httpRequestFactory).build();

}

报错信息如下:

org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest": Connect to pro-api.coinmarketcap.com:443 [pro-api.coinmarketcap.com/13.35.121.116, pro-api.coinmarketcap.com/13.35.121.31, pro-api.coinmarketcap.com/13.35.121.107] failed: Read timed out; nested exception is org.apache.http.conn.ConnectTimeoutException: Connect to pro-api.coinmarketcap.com:443 [pro-api.coinmarketcap.com/13.35.121.116, pro-api.coinmarketcap.com/13.35.121.31, pro-api.coinmarketcap.com/13.35.121.107] failed: Read timed out

at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:696)

at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:622)

at com.chinawkb.monitor.service.impl.CoinMarketServiceImpl.getData(CoinMarketServiceImpl.java:58)

at com.chinawkb.monitor.service.impl.CoinMarketServiceImpl.updateTokenInfos(CoinMarketServiceImpl.java:39)

at com.chinawkb.monitor.EthereumMonitorApplication$Test.run(EthereumMonitorApplication.java:59)

at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:792)

at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:776)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)

at com.chinawkb.monitor.EthereumMonitorApplication.main(EthereumMonitorApplication.java:38)

Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to pro-api.coinmarketcap.com:443 [pro-api.coinmarketcap.com/13.35.121.116, pro-api.coinmarketcap.com/13.35.121.31, pro-api.coinmarketcap.com/13.35.121.107] failed: Read timed out

at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)

at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:373)

at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:394)

at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)

at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)

at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)

at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)

at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)

at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)

at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)

at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)

at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)

at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)

at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:687)

... 10 common frames omitted

Caused by: java.net.SocketTimeoutException: Read timed out

at java.net.SocketInputStream.socketRead0(Native Method)

at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)

at java.net.SocketInputStream.read(SocketInputStream.java:171)

at java.net.SocketInputStream.read(SocketInputStream.java:141)

at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)

at sun.security.ssl.InputRecord.read(InputRecord.java:503)

at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)

at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)

at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)

at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)

at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)

at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355)

at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)

... 23 common frames omitted

已确认rest接口是可以访问的(同一台机器上的postMan可以正常运行)

有没有人遇到过,求教!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值