簡體   English   中英

Spring RestTemplate無法解析尤里卡名稱

[英]spring RestTemplate not resolving eureka names

我有1個eureka服務器和2個微服務。 它們稱為oauth和身份驗證。 我啟動了所有內容,然后2個微服務注冊到了eureka。 我可以通過在瀏覽器中鍵入eureka服務器的URL進行驗證。

我現在想使用一個resttemplate,以便oauth微服務可以與身份驗證微服務通信。

在我的課堂上,我添加了自動接線

@Autowired
private RestTemplate restTemplate;

然后,我使用以下代碼從oauth微服務與身份驗證微服務進行通信。

ResponseEntity<ResponseDto<?>> responseEntity = restTemplate.exchange("http://authentication/api/authentication/verify",
            HttpMethod.POST, request, typeRef);`

執行此代碼后,我會在日志中看到以下內容:

oauth    | 2018-11-30 13:41:58.535  INFO 1 --- [nio-9001-exec-1] s.c.a.AnnotationConfigApplicationContext : Refreshing SpringClientFactory-authentication: startup date [Fri Nov 30 13:41:58 GMT 2018]; parent: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6743e411
oauth    | 2018-11-30 13:41:58.641  INFO 1 --- [nio-9001-exec-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
oauth    | 2018-11-30 13:41:59.115  INFO 1 --- [nio-9001-exec-1] c.netflix.config.ChainedDynamicProperty  : Flipping property: authentication.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
oauth    | 2018-11-30 13:41:59.150  INFO 1 --- [nio-9001-exec-1] c.n.u.concurrent.ShutdownEnabledTimer    : Shutdown hook installed for: NFLoadBalancer-PingTimer-authentication
oauth    | 2018-11-30 13:41:59.221  INFO 1 --- [nio-9001-exec-1] c.netflix.loadbalancer.BaseLoadBalancer  : Client: authentication instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=authentication,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
oauth    | 2018-11-30 13:41:59.237  INFO 1 --- [nio-9001-exec-1] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
oauth    | 2018-11-30 13:41:59.303  INFO 1 --- [nio-9001-exec-1] c.netflix.config.ChainedDynamicProperty  : Flipping property: authentication.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
oauth    | 2018-11-30 13:41:59.310  INFO 1 --- [nio-9001-exec-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client authentication initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=authentication,current list of Servers=[{MYSERVERSIP}:9003],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]
oauth    | },Server stats: [[Server:{MYSERVERSIP}:9003; Zone:defaultZone;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 00:00:00 GMT 1970;  First connection made: Thu Jan 01 00:00:00 GMT 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
oauth    | ]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@1c33a40d
oauth    | 2018-11-30 13:42:00.250  INFO 1 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty  : Flipping property: authentication.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
oauth    | 2018-11-30 13:44:06.826  INFO 1 --- [nio-9001-exec-1] o.s.s.o.provider.endpoint.TokenEndpoint  : Handling error: InternalAuthenticationServiceException, I/O error on POST request for "http://authentication/api/authentication/verify": Operation timed out (Connection timed out); nested exception is java.net.ConnectException: Operation timed out (Connection timed out)

我可以從家用計算機訪問身份驗證微服務,這意味着該端口已打開。 我嘗試了@LoadBalanced批注,但是不起作用。

到底是怎么回事?????

我找到了解決方案。 原來我有一個iptables規則阻止了該請求。 因此,如果您遇到這種情況,請檢查iptables規則。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM