出现以下报错时For ‘gulimall-coupon’ URL not provided. Will try picking an instance via load-balancing
完整报错:
1-10-12 16:54:54.197 INFO 11276 --- [ main] o.s.c.openfeign.FeignClientFactoryBean : For 'gulimall-coupon' URL not provided. Will try picking an instance via load-balancing.
2021-10-12 16:54:54.200 WARN 11276 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberController': Unsatisfied dependency expressed through field 'couponFeignService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.tao.gulimall.member.feign.CouponFeignService': Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?
2021-10-12 16:54:54.202 INFO 11276 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-10-12 16:54:54.214 INFO 11276 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-10-12 16:54:54.241 ERROR 11276 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberController': Unsatisfied dependency expressed through field 'couponFeignService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.tao.gulimall.member.feign.CouponFeignService': Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.7.jar:5.3.7]
从报错的意思可知道,在注册中心中没发现gulimall-coupon这个微服务,有两种大的方向可找出该错误
一、gulimall-coupon这个微服务根本就没注册进去,有以下几种可能
- 微服务没打开
- 在注解里面gulimall-coupon名字写错了
二、本身微服务出现问题,自己没注册进nacos,可能是写yml文件时出错,仔细找一下
我自己出错是,调用者的微服务没注册进去,名字写错位置了
修改后
大家写配置文件的时候一定要小心!!