1.问题描述
在RestTemplate添加@LoadBalanced注解后运行报错
java.lang.IllegalStateException: No instances available for localhost
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:119) ~[spring-cloud-netflix-ribbon-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:99) ~[spring-cloud-netflix-ribbon-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:58) ~[spring-cloud-commons-2.2.5.RELEASE.jar:2.2.5.RELEASE]
2.问题解决
添加@LoadBalanced注解后,请求时需将请求的地址改成服务名称
3.测试结果
4.文章参考链接
a. https://songzixian.com/springcloud/449.html