Spring Cloud Ribbon负载均衡配置类放在Spring boot主类同级增加Exclude过滤后报Field config in com.cloud.web.controller.Rib

本文主要是介绍Spring Cloud Ribbon负载均衡配置类放在Spring boot主类同级增加Exclude过滤后报Field config in com.cloud.web.controller.Rib,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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

  

1
2
public  @interface  ExcludeFromComponetScan {
}

  2、spring cloud启动加载类:

  

1
2
3
4
5
6
7
8
9
10
11
12
@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

  

1
2
3
4
5
6
7
8
9
10
11
12
13
//这个类不能喝Spring Boot @ConponentScan所在主类放在同一个包或其子包下,否则需要些Exclude类做区分
@ExcludeFromComponetScan
@Configuration
public  class  RibbonConfiguration {
     @Autowired
     IClientConfig config;
     @Bean
     public  IRule ribbonRule(IClientConfig config) {
         //随机算法
         return  new  RandomRule();
     }
}
转自:https://www.cnblogs.com/dbaxyx/p/8808940.html

这篇关于Spring Cloud Ribbon负载均衡配置类放在Spring boot主类同级增加Exclude过滤后报Field config in com.cloud.web.controller.Rib的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/182850

相关文章

springboot的调度服务与异步服务使用详解

《springboot的调度服务与异步服务使用详解》本文主要介绍了Java的ScheduledExecutorService接口和SpringBoot中如何使用调度线程池,包括核心参数、创建方式、自定... 目录1.调度服务1.1.JDK之ScheduledExecutorService1.2.spring

MySQL 中的服务器配置和状态详解(MySQL Server Configuration and Status)

《MySQL中的服务器配置和状态详解(MySQLServerConfigurationandStatus)》MySQL服务器配置和状态设置包括服务器选项、系统变量和状态变量三个方面,可以通过... 目录mysql 之服务器配置和状态1 MySQL 架构和性能优化1.1 服务器配置和状态1.1.1 服务器选项

SpringBoot整合easy-es的详细过程

《SpringBoot整合easy-es的详细过程》本文介绍了EasyES,一个基于Elasticsearch的ORM框架,旨在简化开发流程并提高效率,EasyES支持SpringBoot框架,并提供... 目录一、easy-es简介二、实现基于Spring Boot框架的应用程序代码1.添加相关依赖2.添

SpringBoot中整合RabbitMQ(测试+部署上线最新完整)的过程

《SpringBoot中整合RabbitMQ(测试+部署上线最新完整)的过程》本文详细介绍了如何在虚拟机和宝塔面板中安装RabbitMQ,并使用Java代码实现消息的发送和接收,通过异步通讯,可以优化... 目录一、RabbitMQ安装二、启动RabbitMQ三、javascript编写Java代码1、引入

spring-boot-starter-thymeleaf加载外部html文件方式

《spring-boot-starter-thymeleaf加载外部html文件方式》本文介绍了在SpringMVC中使用Thymeleaf模板引擎加载外部HTML文件的方法,以及在SpringBoo... 目录1.Thymeleaf介绍2.springboot使用thymeleaf2.1.引入spring

Spring AI集成DeepSeek的详细步骤

《SpringAI集成DeepSeek的详细步骤》DeepSeek作为一款卓越的国产AI模型,越来越多的公司考虑在自己的应用中集成,对于Java应用来说,我们可以借助SpringAI集成DeepSe... 目录DeepSeek 介绍Spring AI 是什么?1、环境准备2、构建项目2.1、pom依赖2.2

Spring Cloud LoadBalancer 负载均衡详解

《SpringCloudLoadBalancer负载均衡详解》本文介绍了如何在SpringCloud中使用SpringCloudLoadBalancer实现客户端负载均衡,并详细讲解了轮询策略和... 目录1. 在 idea 上运行多个服务2. 问题引入3. 负载均衡4. Spring Cloud Load

Springboot中分析SQL性能的两种方式详解

《Springboot中分析SQL性能的两种方式详解》文章介绍了SQL性能分析的两种方式:MyBatis-Plus性能分析插件和p6spy框架,MyBatis-Plus插件配置简单,适用于开发和测试环... 目录SQL性能分析的两种方式:功能介绍实现方式:实现步骤:SQL性能分析的两种方式:功能介绍记录

在 Spring Boot 中使用 @Autowired和 @Bean注解的示例详解

《在SpringBoot中使用@Autowired和@Bean注解的示例详解》本文通过一个示例演示了如何在SpringBoot中使用@Autowired和@Bean注解进行依赖注入和Bean... 目录在 Spring Boot 中使用 @Autowired 和 @Bean 注解示例背景1. 定义 Stud

解决jupyterLab打开后出现Config option `template_path`not recognized by `ExporterCollapsibleHeadings`问题

《解决jupyterLab打开后出现Configoption`template_path`notrecognizedby`ExporterCollapsibleHeadings`问题》在Ju... 目录jupyterLab打开后出现“templandroidate_path”相关问题这是 tensorflo