问题原因网上有好几种解决方案,我分别列在下边希望能帮到你
这个最好启动类和远程fegin都能在统一的包名下边,确保能扫描到fegin接口
这里写目录标题
- 错误如下:
- 解决办法1
- 解决方案2
错误如下:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bizLeaveController': Unsatisfied dependency expressed through field 'bizLeaveService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bizLeaveServiceImpl': Unsatisfied dependency expressed through field 'sysClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.zhby.inter.client.SysClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-netflix-ribbon?at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1420)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)at com.zhby.ActivityApplication.main(ActivityApplication.java:25)
解决办法1
添加spring-cloud-starter-loadbalancer,排除 Nacos 的 Ribbon
原因是因为这个冲突了好像
<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>
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-loadbalancer</artifactId><version>2.2.1.RELEASE</version>
</dependency>
解决方案2
出现以下情况:少了服务引用了 加上以下即可
No Feign Client for loadBalancing defined.
Did you forget to include spring-cloud-starter-netflix-ribbon?
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>