RestTemplate/HTTPClient出现java.net.UnknownHostException:XXXX.XXXX.com解决办法
最编程
2024-03-19 12:31:27
...
在项目中,一个主系统需要向多个子系统分发数据(RestTemplate)。项目接口都是通过域名请求访问。每当调用到一定阶段后都会出现未知域名,导致请求数据失败。以下是错误内容
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://xxx.com/dataSync/updateJson": xxx.com; nested exception is java.net.UnknownHostException: xxx.com
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:607) ~[spring-web-4.2.8.RELEASE.jar:4.2.8.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557) ~[spring-web-4.2.8.RELEASE.jar:4.2.8.RELEASE]
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:357) ~[spring-web-4.2.8.RELEASE.jar:4.2.8.RELEASE]
at com.app.cq.utils.RestTemplateUtils.pushData(RestTemplateUtils.java:31) ~[classes/:?]
原因: 在host文件里面主机名和本地循环地址没有匹配到。 需要在hosts文件中添加上该域名的解析ip地址。
linux服务器
vi /etc/hosts
#添加以下一行内容
域名的解析ip 域名
执行service network restart 使之生效
windows服务器
打开windws/system32/driver/etc/hosts,添加以下内容
域名的解析ip 域名