我已经创建了 Spring boot 应用程序并使用 REST API 开发并部署在具有 DNS 名称的其他服务器上。
@FeignClient(url="${env.app.crm.url}", value= "crm-feign-client", path ="/CRM/API", configuration = CRMFeignConfiguration.class)
@Headers("Content-Type: application/json")
public interface CRMFeignClients {
成功场景:
失败案例:
以下是日志:
**feign.RetryableException: <HOST NAME**> executing POST http://<**HOST NAME AND CONTEXT PATH**>/UpdateCustomer
at feign.FeignException.errorExecuting(FeignException.java:268)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:131)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:91)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100)
at com.sun.proxy.$Proxy176.updateCustomer(Unknown Source)
at com.kafd.outbound.services.KAFDCrmService.callCustomerUpdateService(KAFDCrmService.java:107)
at com.kafd.outbound.services.KAFDBackgroundService.CustomerDataPush(KAFDBackgroundService.java:81)
at com.kafd.outbound.services.KAFDBackgroundService$$FastClassBySpringCGLIB$$add32094.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
**Caused by: java.net.UnknownHostException**: <**MY HOST NAME**>
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
at sun.net.www.http.HttpClient.New(HttpClient.java:308)
at sun.net.www.http.HttpClient.New(HttpClient.java:326)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1169)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1105)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:999)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:933)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1283)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1258)
at feign.Client$Default.convertAndSend(Client.java:208)
at feign.Client$Default.execute(Client.java:105)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:121)
我知道现在已经过去一年多了,但我遇到了一个非常相似的问题。 这可能不是解决方案,但我仍然会分享我的解决方案,以防它有帮助或对其他人有帮助。
在
@FeignClient
属性的注释 url
中,仅放置主机名是不够的。我还必须包含我想要访问的服务的名称。
因此,在这种情况下,您的
env.app.crm.url
属性应如下所示:
env.app.crm.url=<your-hosts-ip>/<service-name>