【问题标题】:Bean of type 'com.netflix.client.config.IClientConfig' that could not be found找不到类型为“com.netflix.client.config.IClientConfig”的 Bean
【发布时间】:2019-04-02 20:15:46
【问题描述】:

我的功能区应用程序出现问题。这是我的代码:

@SpringBootApplication
@EnableDiscoveryClient
@RestController
@RibbonClient(name= "bye", configuration=RibbonConfig.class )
public class RibbonAppApplication {
    @Autowired
    private RestTemplate restTemplate;
    public static void main(String[] args) {
        SpringApplication.run(RibbonAppApplication.class, args);
    }
    @GetMapping
    public String getService() {
        return restTemplate.getForObject("http://bye",String.class);
    }
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}

还有我的RibbonConfig.class

@Configuration
public class RibbonConfig {
    
    @Bean
    public IPing ribbonPing(IClientConfig config) {
        return new PingUrl(false,"/health");
    }
  
    @Bean
    public IRule ribbonRule(IClientConfig config) {
        return new AvailabilityFilteringRule();
    }
}

但是,我收到以下错误:

在 practice.zuul.zach.ribbonapp.RibbonConfig 中的方法ribbonPing 的参数 0 需要一个无法找到的 'com.netflix.client.config.IClientConfig' 类型的 bean。

行动: 考虑在您的配置中定义“com.netflix.client.config.IClientConfig”类型的 bean。

有什么办法可以解决吗?

【问题讨论】:

  • 自动装配 IClientConfig。
  • 感谢您的建议!请问如何自动装配IClientConfig?这是一个参数
  • @Autowired IClientConfigribbonClientConfig;还是一样的错误
  • @JaisAnkit 这里作为参数传递和类中的自动装配是一回事

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


【解决方案1】:

当我在 RibbonAppApplication 类中添加这一行时问题解决了

@SpringBootApplication(scanBasePackages={"com.netflix.client.config.IClientConfig"})

【讨论】:

  • 但如果你这样做。它将排除您的ribbonclientconfig 实现
  • 这个答案是错误的。 IClientConfig 是一个接口!
猜你喜欢
  • 2018-12-16
  • 2019-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-22
  • 2018-06-12
  • 1970-01-01
相关资源
最近更新 更多