Spring Cloud Ribbon负载均衡配置类放在Spring boot主类同级增加Exclude过滤后报Field config in com.cloud.web.controller.RibbonConfiguration required a bean of type 'com.netflix.client.config.IClientConfig' that could not b
环境:
Spring Cloud:Finchley.M8
Spring Boot:2.0.0.RELEASE
目录结构:

可以看到代码第13行的注释,我已经在@ComponentScan注解中添加了Exclude配置项,但是启动服务的时候还是报如下的错误:
2018-04-12 15:59:37.815 WARN 17828 --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method 'close' failed on bean with name 'eurekaRegistration': org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
2018-04-12 15:59:37.825 INFO 17828 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-04-12 15:59:37.828 WARN 17828 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [spring.cloud.inetutils] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.net.Inet6AddressImpl.getHostByAddr(Native Method)
java.net.InetAddress$2.getHostByAddr(InetAddress.java:932)
java.net.InetAddress.getHostFromNameService(InetAddress.java:617)
java.net.InetAddress.getHostName(InetAddress.java:559)
java.net.InetAddress.getHostName(InetAddress.java:531)
org.springframework.cloud.commons.util.InetUtils$2.call(InetUtils.java:162)
org.springframework.cloud.commons.util.InetUtils$2.call(InetUtils.java:159)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
2018-04-12 15:59:37.838 INFO 17828 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-04-12 15:59:37.961 ERROR 17828 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : ***************************
APPLICATION FAILED TO START
*************************** Description: Field config in com.cloud.web.controller.RibbonConfiguration required a bean of type 'com.netflix.client.config.IClientConfig' that could not be found. Action: Consider defining a bean of type 'com.netflix.client.config.IClientConfig' in your configuration. Process finished with exit code 1
日志关键点在倒数第二行,其实原因很简单ComponentScan不去扫单个Ribbon的配置(RibbonConfigureration)不应用于所有Ribbon客户端,那这个当个客户端去加载的时候就要让Component知道不去管理他,否则就回去扫一遍,看我的Ribbon配置类,55行,被我注释了,没有引用到Exclude注解,所以还是去扫了:

问题很简单,把注解加上就好了。。
贴一下几个类的代码:
1、ExcludeFromComponetScan
public @interface ExcludeFromComponetScan {
}
2、spring cloud启动加载类:
@EnableAutoConfiguration
//excludeFilters这里的意思是,只要标有ExcludeFromComponetScan注解的类都不会去扫描
@ComponentScan(value = "com.cloud", excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value=ExcludeFromComponetScan.class)})
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableEurekaClient
@RibbonClient(name = "SPRING-CLOUD-WEB-PROVIDER", configuration = RibbonConfiguration.class)
public class SpringCloudRibbonApplication { public static void main(String[] args) {
SpringApplication.run(SpringCloudRibbonApplication.class, args);
}
}
3、RibbonConfiguration
//这个类不能喝Spring Boot @ConponentScan所在主类放在同一个包或其子包下,否则需要些Exclude类做区分
@ExcludeFromComponetScan
@Configuration
public class RibbonConfiguration {
@Autowired
IClientConfig config; @Bean
public IRule ribbonRule(IClientConfig config) {
//随机算法
return new RandomRule();
}
}
Spring Cloud Ribbon负载均衡配置类放在Spring boot主类同级增加Exclude过滤后报Field config in com.cloud.web.controller.RibbonConfiguration required a bean of type 'com.netflix.client.config.IClientConfig' that could not b的更多相关文章
- spring-cloud: eureka之:ribbon负载均衡配置(一)
spring-cloud: eureka之:ribbon负载均衡配置(一) 比如我有: 一个eureka服务:8761 两个user用户服务: 7900/7901端口 一个movie服务:8010 1 ...
- spring eureka required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found.
spring在集成第三方过程很容易出现类名相同,且基本作用相同的类.这样给初学者带来一定的困惑. 导致用错类而出现以下问题. required a bean of type 'com.netflix. ...
- spring cloud: zuul(三): ribbon负载均衡配置
zuul的routes配置下path/url组合不支持负载均衡 下面介绍zuul的routes配置下的path/serviceId负载均衡配置 spring-boot-user微服务开启了:7901, ...
- Spring Cloud06: Ribbon 负载均衡
一.使用背景 前面的学习中,我们已经使用RestTemplate来实现了服务消费者对服务提供者的调用,如果在某个具体的业务场景下,对某个服务的调用量突然大幅提升,这个时候就需要对该服务实现负载均衡以满 ...
- SpringCloud之Ribbon负载均衡配置
一.负载均衡解决方案分类及特征 业界主流的负载均衡解决方案有: 1.1 集中式负载均衡 即在客户端和服务端之间使用独立的负载均衡设施(可以是硬件,如F5, 也可以是软件,如nginx), 由该设施负责 ...
- Spring Cloud Ribbon负载均衡
目录 一.简介 二.客户端负载均衡 三.RestTemplate详解 GET请求 POST请求 PUT请求 DELETE请求 一.简介 Spring Cloud Ribbon是一个基于HTTP 和 ...
- Spring Cloud Ribbon负载均衡(快速搭建)
Spring Cloud Ribbon 是一个基于HTTP和TCP的客户端负载均衡工具,它基于Netflix Ribbon实现.通过 Spring Cloud 的封装, 可以让我们轻松地将面向服务的 ...
- SpringCloud微服务实战二:Spring Cloud Ribbon 负载均衡 + Spring Cloud Feign 声明式调用
1.Spring Cloud Ribbon的作用 Ribbon是Netflix开发的一个负载均衡组件,它在服务体系中起着重要作用,Pivotal将其整合成为Spring Cloud Ribbon,与其 ...
- spring boot 2.0 ribbon 负载均衡配置
1.pom.xml <dependency> <groupId>org.springframework.cloud</groupId> <artifactId ...
随机推荐
- centos7用docker安装mysql5.7.24后配置主从
1)使用docker安装完成mysql5.7.24,我规划的是3台: 192.168.0.170(Master) 192.168.0.169(Slave) 192.168.0.168(Slave) 2 ...
- #首行输入数n,接下来输入n行数,以空格隔开
#首行输入数n,接下来输入n行数,以空格隔开 n = int(raw_input())# print nL = []for i in range(n): L.append([int(x) for x ...
- POJ-1321-棋盘问题(深搜)
棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65409 Accepted: 31227 Descriptio ...
- 分享记录一批免费VIP视频解析接口,不定时更新!
VIP视频接口的作用相信大家都懂,那么,由于接口的维护.开发具有不稳定性,失效率很高.这里收集一些目前可用的接口,如果不能用,请反馈给我删除,感谢大家! 电影<西虹市首富>优酷链接:htt ...
- CentOS 中安装 mysql 5.7+
参考:https://www.cnblogs.com/jimboi/p/6405560.html 1.下载rpm文件 wget https://dev.mysql.com/get/mysql57-co ...
- 在 Domoticz 中添加插座开关
前言 继上一篇的折腾,将 WiFi 插座刷为 ESPEasy,这次介绍一下在 Domoticz 中启用该插座的方法 步骤 在 Domoticz 控制台,设置 → 硬件中添加 Dummy,名称为&quo ...
- 极限编程(xp),iso国际标准化组织
极限编程(xp):eXtreme Programming 极限编程-XP 四个价值:沟通 communication.简化 similicity.反馈 feedback.勇气 courage http ...
- LeetCode记录之35——Search Insert Position
这道题难度较低,没有必要作说明. Given a sorted array and a target value, return the index if the target is found. I ...
- Luogu P1272 重建道路 树形DP
刚才瞅了半天自己当初写的,终于瞅出来了...QWQ 设f[i][j]表示以i为根的子树,包含j个节点所需砍掉的最小边数 那么可知f[u][1]=u的度: 方程:f[u][j]=min(f[u][j], ...
- vim(三)golang代码跳转配
在golang的代码里跳来跳去.... godef 安装 跳转是通过godef实现,godef的安装目录一般是$GOBIN,只要让godef命令在$PATH下即可 godef 命令安装: go get ...