-
首先 新版的 Spring Cloud Alibaba 中 , 底层没有了 loadbalancer 依赖,所以在 使用OpenFeign时会导致Bean注入出问题,导入以下依赖即可
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> <version>3.1.0</version> </dependency>
-
在 Nacos中 有 netflix-ribbon 这个包, 这个包 和 loadbalancer 有冲突,所以去掉该包
<!-- 剔除ribbon的 nacos 依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</exclusion>
</exclusions>
</dependency>
- SpringCloud Alibaba 和 OpenFeign的依赖
<!-- spring-cloud-alibaba-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>