SpringCloud - 整合Nacos启动报错Consider defining a bean of type IClientConfig

  • 前言
  • 一. 尝试解决Bug的几种不合适方案
    • 1.1 添加ribbon依赖
    • 1.2 按照提示增加IClientConfig配置
    • 1.3 正确答案

前言

我写了一套网关服务,一模一样的代码在自己电脑和公司电脑都写了一份。结果:

  • 公司电脑:启动报错。
  • 自己电脑:正常运行。

代码一模一样,最终发现,有一处不同:

  • 公司电脑:包名以com为开头。

  • 自己电脑:包名不是以com为开头。

最终启动报错如下:

再说结果之前,先说一下我从网上找过的各种解决方案。因为网上大多都是这几种方案,但是具体问题得具体分析。这里先排个雷(仅针对于包名为com的情况)

一. 尝试解决Bug的几种不合适方案

1.1 添加ribbon依赖

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-ribbon</artifactId><version>2.1.0.RELEASE</version>
</dependency>

添加后,依旧报错。不可行。

1.2 按照提示增加IClientConfig配置

在配置类中增加一个Bean

@Bean
public IClientConfig iClientConfig() {return new DefaultClientConfigImpl();
}

添加之后启动正常。但是!但是!但是我发送请求到网关,然后网关再进行转发的时候,就出大问题了:

详细信息:

  1. Error creating bean with name 'ribbonLoadBalancingHttpClient' defined in org.springframework.cloud.netflix.ribbon.apache.HttpClientRibbonConfiguration:
  2. Unsatisfied dependency expressed through method 'ribbonLoadBalancingHttpClient' parameter 2

也就是说创建ribbonLoadBalancingHttpClient这个Bean的时候出了问题。然后构造函数是有问题的。需要两个参数。具体原因不往下分析了。反正问题代码就出在上面的配置Bean

return new DefaultClientConfigImpl();

虽然增加它,可以避免启动错误,但是无法阻挡这种运行时错误,比如这种构造函数的调用出错。

1.3 正确答案

把上面几种方案都去除。然后将包名改为非com。原因:

  1. Nacos在启动的时候,就会扫描以com为开头的包。此时需要加载路径为com.netflix.client.config.IClientConfig的相关实例。
  2. 然后我们的包名恰恰以com为开头,可能优先扫描本地项目,就会发现找不到这个类,就会报错。无法启动。

当然,上面的是我的一个猜想,但是如果本地项目使用com为开头的话,肯定是存在一定的冲突的。

附带springcloudgithub相关问题IClientConfig找不到,官网上也有其他的解决方案。看看能不能帮到大家。

SpringCloud - 整合Nacos启动报错Consider defining a bean of type IClientConfig相关推荐

  1. 解决启动报错Consider defining a bean of type ‘xxx‘ in your configuration.

    解决启动报错Consider defining a bean of type 'xxx' in your configuration. 报错截图 解决方法:查看注解是否同时存在@AllArgsCons ...

  2. springboot启动报错: Consider defining a bean of type ‘XXX‘ in your configuration

    Consider defining a bean of type 'XXX' in your configuration 出现这个错误,要看看你是否用到了某些组件,但是启动类上没加相应的注解.比如说我 ...

  3. SpringBoot启动报错Consider defining a bean of type ‘com.test.springmvc.dao.xx‘ in your configuration.

    报错信息如下: Description:Field userDao in com.test.springmvc.service.impl.UserServiceImpl required a bean ...

  4. Spring Cloud/Boot启动报错Consider defining a bean of type ServerCodecConfigurer

    网关项目启动报错内容如下: Error starting ApplicationContext. To display the conditions report re-run your applic ...

  5. 【微服务】 网关启动报错 Consider defining a bean of type org.springframework.http.codec.ServerCodecConfigurer

    一.现象 微服务启动时报错:Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer ...

  6. 学习记录报错Consider defining a bean of type ‘org.springframework.web.client.RestTemplate‘ in your configu

    springboot启动就报错 信息如下 Field restTemplate in com.atguigu.springcloud.controller.OrderController requir ...

  7. spring boot 启动报错:No qualifying bean of type org.springframework.security.oauth2.provider.token.Toke

    spring boot启动报错: Exception encountered during context initialization - cancelling refresh attempt: o ...

  8. 项目启动报错:No qualifying bean of type ‘xxx‘ available:

    项目启动报错: Description: A component required a bean of type 'cn.hsa.its.abutment.bo.BusinessAcceptBo' t ...

  9. springboot 启动报错:required a bean of type 'xxxRepository' that could not be found

    springboot启动的时候报错,错误如下: Field demoRepository in com.ge.serviceImpl.DemoServiceImpl required a bean o ...

最新文章

  1. WebSocket客户端断开连接后,服务器端的处理机制
  2. 计算机系统结构——概述
  3. 启动rrt什么意思_python学习第144课--创建虚拟机、设置虚拟机参数以及启动虚拟机...
  4. 1003 Express Mail Taking
  5. (转)OpenLayers3基础教程——OL3基本概念
  6. NLTK基础教程学习笔记(二)
  7. .Net 4.0 之 Dynamic 动态类型
  8. Java进阶之路,技术要点
  9. vue项目中配置eslint和prettier
  10. 菜鸟上网必备知识大全
  11. 元件封装尺寸_单位换算表
  12. 用计算机如何算行列式,数学计算器使用操作步骤
  13. 基于大数据的资金流量分析:思路与应用前景设想
  14. Minecraft Forge Mod 开发笔记
  15. css钢铁侠视角,css练习制作钢铁侠胸口的小型核反应堆
  16. 618值得囤的好书清单
  17. 前端js、功能性工具插件网站(持续更新,欢迎分享)
  18. 2. 将文件中每一行字符反序
  19. JS 大杂烩(持续更新)
  20. 字符串之正则表达式匹配

热门文章

  1. 微信无法拍摄小视频问题
  2. 程序设计基础(CC++) 戴波、张东祥 第五章 指针 编程作业
  3. 我的世界java如何加好友进世界_我的世界中国版怎么添加好友 好友开黑联网方法...
  4. Facebook开发AI语音助手,或是“钱途”未卜
  5. 怎么在java中引用图片_如何使用Java(读/写)读取复制和粘贴图片?
  6. Synchronized偏向锁、轻量级锁、重量级锁详解
  7. RabbitMQ消息队列常见面试题总结
  8. 多回路限流式保护箱在电动汽车充电站的应用-安科瑞耿敏花
  9. 20几岁决定男人的一生(摘抄)
  10. 李开复——如何平衡你的工作和家庭