spring-cloud的Feign报错处理

Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-netflix-ribbon?
    at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:241) ~[spring-cloud-openfeign-core-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:267) ~[spring-cloud-openfeign-core-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:247) ~[spring-cloud-openfeign-core-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    ... 30 common frames omitted

 

看网上老是说引用eureka就可以了,我也引用了,但是还不行,结果发现

 

spring-cloud-starter-netflix-eureka-client和spring-cloud-netflix-eureka-client区别

 

要引用spring-cloud-starter-netflix-eureka-client才行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,如果你使用的是 Spring Boot 2.1.8.RELEASE,那么你需要使用 Spring Cloud Greenwich 版本的依赖。你可以在你的 pom.xml 文件中添加以下依赖来引入 Spring Cloud Greenwich 版本的 OpenFeign: ``` <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <version>Greenwich.SR3</version> </dependency> ``` 如果你已经引入了正确版本的依赖,但是仍然遇到了问题,可以尝试以下解决方案: 1. 确保你的 `@SpringBootApplication` 注解所在的类的包路径是正确的。如果你的 `@SpringBootApplication` 注解所在的类位于根包路径下,而其他组件的包路径却不是根包路径下,那么你需要在启动类上添加 `@ComponentScan` 注解,来指定其他组件的包路径,例如: ``` @SpringBootApplication @ComponentScan(basePackages = "com.example.other") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` 2. 确保你的 `@EnableFeignClients` 注解所在的类的包路径是正确的。同样的,如果你的 `@EnableFeignClients` 注解所在的类位于根包路径下,而其他组件的包路径却不是根包路径下,那么你需要在 `@EnableFeignClients` 注解中指定其他组件的包路径,例如: ``` @SpringBootApplication @EnableFeignClients(basePackages = "com.example.other") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` 3. 确保你的 Feign 接口定义的路径是正确的。例如,如果你的 Feign 接口定义的路径是 `/api/service`,那么你的请求 URL 应该是 `http://localhost:8080/api/service`,而不是 `http://localhost:8080/service`。 希望这些解决方案能够帮助你解决问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值