【问题标题】:No qualifying bean of type 'com.netflix.client.config.IClientConfig' available:expected at least 1 bean which qualifies as autowire candidate没有可用的“com.netflix.client.config.IClientConfig”类型的合格 bean:预计至少有 1 个有资格作为自动装配候选者的 bean
【发布时间】:2020-05-31 00:17:06
【问题描述】:

我正在使用 Netflix 圆形功能区创建负载均衡器,但我无法 自动连接IClientConfig这个对象。

我也试过这个 @SpringBootApplication(scanBasePackages{"com.netflix.client.confg.IClientConfig"})

但这也不适合我。

我遇到了这个异常

org.spring framework.beans.factory.NoSuchBeanDefinitionException:没有“com.netflix.client.config.IClientConfig”类型的合格 bean 可用:预计至少有 1 个有资格作为自动装配候选者的 bean。依赖注解:{}

【问题讨论】:

  • 你在IClientConfig类上写过@Service注解或者@Component注解吗?您是在应用程序启动时调用此 bean,还是在应用程序启动后的某个时间点调用此 bean?
  • 是的,我提到了@Configuration 注释这是我的代码@Configuration public class ClientAppConfiguration { @Bean public IRule ribbonRule(IClientConfig config) { System.out.println("HERE"); return new BestAvailableRule(); } @Bean public IPing ribbonPing() { return new PingUrl(); } }
  • 通常这意味着您有一个已被正常应用程序上下文拾取的功能区 bean。这些需要在单独的配置类中定义并由@RibbonClient 注解引用
  • 我有一个单独的类,因为我提到了@RibbonClient 注释,提到了我的配置类名称@RibbonClient(name = "loadbalancer-web", configuration = ClientAppConfiguration.class) @spencergibb
  • 根据文档从该类中删除 @Configuration

标签: spring-boot spring-cloud netflix-ribbon


【解决方案1】:

我怀疑您的依赖项配置不正确。 ribbon-core 是否添加为 build.gradlepom.xml 中的编译依赖项?

请检查是否有

runtime group: 'com.netflix.ribbon', name: 'ribbon-core', version: '2.7.17'

<dependency>
    <groupId>com.netflix.ribbon</groupId>
    <artifactId>ribbon-core</artifactId>
    <version>2.7.17</version>
    <scope>runtime</scope>
</dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 2019-09-25
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多