在@preDestory方法中调用Rest API并在Spring boot应用程序中遇到unknownHostExeception问题

发布于 2025-01-10 21:13:00 字数 2684 浏览 0 评论 0原文

我正在使用 RestTeplate.postForEntity(); 调用 API在@preDestroy注释的方法中。将其部署为 AWS EKS 并使用 kubectl 命令缩小 pod,并且调用 @preDestroy 方法,但 RestTeplate.postForEntity() 调用由于unknownhostException而失败

错误日志:
测试 API 调用失败 org.springframework.web.client.ResourceAccessException:“https://test.com/v2/testprocess/test”的 POST 请求出现 I/O 错误:test.com;嵌套异常是 java.net.UnknownHostException: test.com|在 org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:742)|在 org.springframework.web.client.RestTemplate.execute(RestTemplate.java:689)|在 org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:452)|在 com.test.TestClient.testAPI(c.java:226)|在 com.test.TestClient.testAPI(TestClient.java:52)|引起:java.net.UnknownHostException: test.com|在 java.net.InetAddress.getAllByName0(来源未知)|在 java.net.InetAddress.getAllByName(来源未知)|在 java.net.InetAddress.getAllByName(来源未知)|在 org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)|在 org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:112)|在 org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)|在 org.apache.http.impl.execchain.MainClientExec.builtRoute(MainClientExec.java:393)|在 org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)|在 org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)|在 org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)|在 org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)|在 org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)|在 org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)|在 org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)|在 org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)|在 org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)|在 org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)|在 org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:733)| ... 4 更多


@mozello - thanks for responding, In my app I call the API in two aspect, 1. During the App startup for this i'm using @postConstuctor annotated method and API is call is happening perfectly fine. which means the k8's able to resolve the "test.com" right. But getting this unknownHostException issue only during the @preDestroy method execution, pls suggest.

I'm calling API using RestTeplate.postForEntity(); in the @preDestroy annotated method. Deploying it as AWS EKS and using kubectl command scaling down the pod and the @preDestroy method is getting called but RestTeplate.postForEntity() call is failing due to unknownhostExeception

Error log:
Test API call is failed org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://test.com/v2/testprocess/test": test.com; nested exception is java.net.UnknownHostException: test.com| at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:742)| at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:689)| at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:452)| at com.test.TestClient.testAPI(c.java:226)| at com.test.TestClient.testAPI(TestClient.java:52)|Caused by: java.net.UnknownHostException: test.com| at java.net.InetAddress.getAllByName0(Unknown Source)| at java.net.InetAddress.getAllByName(Unknown Source)| at java.net.InetAddress.getAllByName(Unknown Source)| at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)| at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:112)| at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)| at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)| at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)| at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)| 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:733)| ... 4 more

@mozello - thanks for responding, In my app I call the API in two aspect, 1. During the App startup for this i'm using @postConstuctor annotated method and API is call is happening perfectly fine. which means the k8's able to resolve the "test.com" right.
But getting this unknownHostException issue only during the @preDestroy method execution, pls suggest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文