kma*_*bet 3 spring-boot spring-cloud netflix-eureka
根据这篇博客https://spring.io/blog/2015/07/14/microservices-with-spring
能够毫无问题地运行应用程序.按此顺序:
但是当尝试通过Web应用程序(http:// localhost:3333 /)使用http:// ACCOUNTS-SERVICE URL访问任何帐户服务端点(如http:// ACCOUNTS-SERVICE/accounts/123456789)时,我收到错误回复:
Response Status: 500 (Internal Server Error)
Cause: org.springframework.web.client.ResourceAccessException I/O error on GET request for "http://ACCOUNTS-SERVICE/accounts/123456789": ACCOUNTS-SERVICE; nested exception is java.net.UnknownHostException: ACCOUNTS-SERVICE
Run Code Online (Sandbox Code Playgroud)
当我向Web服务器而不是http:// ACCOUNTS-SERVICE提供帐户服务的真实地址(http:// localhost:2223 /)时,一切正常,但在这种情况下没有服务发现.
kma*_*bet 16
此问题是由于Restrimplate不再在Brixton发布列车(Spring Cloud 1.1.0.RELEASE)中自动创建,因此RestTemplate无法使用服务发现服务器正确解析http:// ACCOUNTS-SERVICE URL .
在使用@LoadBalanced声明RestTemplate bean之后能够解决此问题,如下所示:
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8196 次 |
| 最近记录: |