java.lang.IllegalStateException:没有为 loadBalancing 定义的假客户端。您是否忘记包含 spring-cloud-starter-netflix-ribbon?
2022-09-04 01:03:48
我遇到异常:
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.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:178)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1654)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1174)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:257)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:224)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1012)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:338)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:333)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)
at com.hsbc.gbgcf.spartan.referencedatabase.UserRegistrationApplication.main(UserRegistrationApplication.java:57)
执行我的项目时。我的绒球.xml含有
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
我也在我的其他项目中使用假客户端,没有任何额外的功能区依赖性,并且这些都使用相同的spring-boot版本2.0.8
我已经为同一问题引用了其他堆栈溢出链接,他们要求添加功能区的其他依赖项。我尝试过在我的pom中添加相同的.xml但它没有帮助。
假装客户端接口是,
@FeignClient(value = "user-service", decode404 = true)
public interface UserFeignClient {
@PostMapping("/do-something")
void doSomething();
}
主类代码:
@Configuration
@EnableAspectJAutoProxy
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"test.user"})
public class UserRegistrationApplication{
public static void main(String[] args) {
UserFeignClient userFeignClient = applicationContext.getBean(UserFeignClient.class);
userFeignClient.doSomething();
System.exit(SpringApplication.exit(applicationContext));
}
}
我使用的是Sprint Boot版本2.0.8。