java.lang.IllegalStateException: No instances available for CLOUD-PROVIDER-SERVICE
原创
©著作权归作者所有:来自51CTO博客作者杉菜酱_的原创作品,请联系作者获取转载授权,否则将追究法律责任
报错信息:java.lang.IllegalStateException: No instances available for CLOUD-PROVIDER-SERVICE
问题背景 :
依次启动eureka集群(7001和7002)、支付服务8001(服务提供者)、支付服务8002(服务提供者)、订单服务89(服务消费者)之后,在http://eureka7001.com:7001/和http://eureka7002.com:7002/的服务注册中心可视化页面中可以看到CLOUD-PROVIDER-SERVICE支付服务集群(8001和8002)已经被注册到eureka服务注册中心了,但是访问http://localhost:89/consumer/payment/getForEntity/1接口时,控制台会报上述异常信息。
解决方法:
我们需要在订单模块的pom依赖中添加以下依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-ribbon</artifactId>
<version>2.2.9.RELEASE</version>
</dependency>
然后重启订单模块,再次访问:http://localhost:89/consumer/payment/getForEntity/1
返回结果正常。
在这里贴出订单服务完整的pom.xml文件 :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cloud2020</artifactId>
<groupId>com.atguigu.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-consumer-order80</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-devtools</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- <optional>true</optional>-->
<!-- </dependency>-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--引入自己定义的api通用包,可以使用Payment支付Entity-->
<dependency>
<groupId>com.atguigu.springcloud</groupId>
<artifactId>cloud-api-commons</artifactId>
<version>${project.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-netflix-eureka-client</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-loadbalancer</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-ribbon</artifactId>
<version>2.2.9.RELEASE</version>
</dependency>
</dependencies>
</project>