我得到了例外:
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)
在执行我的项目时。我的 pom.xml 包含
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
我也在我的其他项目中使用 feign 客户端,没有任何额外的功能区依赖,这些都使用相同的 spring-boot 版本 2.0.8
我已经针对相同的问题引用了其他堆栈溢出链接,他们要求添加功能区的其他依赖项。我尝试在我的 pom.xml 中添加相同的内容,但没有帮助。
FeignClient 接口是,
@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。