【已解决】处理SpringCloud项目ribbon服务调度不生效,提示No instances available for xxx

【已解决】处理SpringCloud项目ribbon服务调度不生效,提示No instances available for xxx_第1张图片

参考Ribbon:Spring Cloud负载均衡与服务调用组件(非常详细) 实践ribbon调度服务功能,使用restTemplate.getForObject(),通过另一个模块的微服务名称BUSINESSSERVICEPROVIDER,获取该模块的地址并调用。

【已解决】处理SpringCloud项目ribbon服务调度不生效,提示No instances available for xxx_第2张图片

但是调用失败,提示:

java.lang.IllegalStateException: No instances available for BUSINESSSERVICEPROVIDER
	at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:119) ~[spring-cloud-netflix-ribbon-2.2.10.RELEASE.jar:2.2.10.RELEASE]
	at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:99) ~[spring-cloud-netflix-ribbon-2.2.10.RELEASE.jar:2.2.10.RELEASE]
	at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:56) ~[spring-cloud-commons-3.0.1.jar:3.0.1]
	at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:93) ~[spring-web-5.3.3.jar:5.3.3]
	at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:77) ~[spring-web-5.3.3.jar:5.3.3]
	at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-5.3.3.jar:5.3.3]
	at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66) ~[spring-web-5.3.3.jar:5.3.3]
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:775) ~[spring-web-5.3.3.jar:5.3.3]
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:710) ~[spring-web-5.3.3.jar:5.3.3]
	at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:333) ~[spring-web-5.3.3.jar:5.3.3]
	at com.springcloud.ribbon.controller.RibbonController.sayHello(RibbonController.java:28) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]

错误原因:

ribbon模块的pom同时引用了spring-cloud-starter-netflix-eureka-clientspring-cloud-starter-netflix-ribbon两个依赖


<dependency>
	<groupId>org.springframework.cloudgroupId>
	<artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
dependency>


<dependency>
	<groupId>org.springframework.cloudgroupId>
	<artifactId>spring-cloud-starter-netflix-ribbonartifactId>
	<version>2.2.10.RELEASEversion>
dependency>

但是spring-cloud-starter-netflix-eureka-client包里面已经包含了spring-cloud-starter-netflix-ribbon,如果再次引入spring-cloud-starter-netflix-ribbon就会造成依赖冲突,所以只引入spring-cloud-starter-netflix-eureka-client即可。

此问题解决办法只针对我的实践项目所遇到的问题,不一定是唯一解决办法,希望对你有一定的帮助。

你可能感兴趣的:(Maven,Spring,Cloud,spring,cloud,ribbon,spring)