目前有三个组件
注册中心,注册者,消费者。
消费者直接调用 restTemplate.getObject(“http://{SERVICE-NAME}”, String.class) 的时候会出现 No instances available 的错误
查阅资料后发现自己的配置中出现的两个问题:
- 消费者的配置文件中没有加入注册中心的地址,随后加入
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8080/eureka/
2. 旧的pom.xml中对于ribbon的依赖是
-
RestTemplate的Bean忘记加入@LoadBalanced注解
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
参考文献:
https://github.com/forezp/SpringCloudLearning/blob/master/chapter2/service-ribbon/src/main/resources/application.yml
https://stackoverflow.com/questions/46747246/ribbon-and-eureka-no-instances-available/50230792#50230792