springcloudAlibaba设置allow-bean-definition-overriding=true不生效问题解决
背景
有个新项目需要启动。
因为有部分业务的请求相对来讲比其它的要强的多。
而且还受到第三方的影响较深
基于这种情况,微服务的使用方式就提上了日程。
原来两年前的微服务架构,考虑到技术的变化,就准备升级了下包
看到最新的2021版本已经出炉了。
解决了那么多的bug,不升级都对不起自己了,关键这个还是新项目,没有负担。
那么就升级最新版本
问题
前面都很OK,在启动服务的时候,提示了以下错误。
***************************
APPLICATION FAILED TO START
***************************Description:The bean 'redisTemplate', defined in class path resource [com/XX/XX/redis/autoconfigure/RedisAutoConfigure.class], could not be registered. A bean with that name has already been defined in class path resource [org/redisson/spring/starter/RedissonAutoConfiguration.class] and overriding is disabled.Action:Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
上面说是因为bean名称重复了,设置spring.main.allow-bean-definition-overriding=true来解决。
但是我实际再bootstrap.yaml中已经设置了当前值。
那么结果已经很明显了,就是spring.main.allow-bean-definition-overriding=true没有生效。
解决方案
既然没有生效,那就让他生效好了。
生效的方式有两个
方案1:代码强制生效
一个是修改代码,在启动的main方法中强制设置allow-bean-definition-overriding=true
public static void main(String[] args) {SpringApplication application = new SpringApplication(ApplicationRun.class);application.setAllowBeanDefinitionOverriding(true);application.run(args);
}
方案2:增加相关依赖包
新的版本中,springcloud把bootstrap等单独拆分了出来。
所以需要单独引入bootstrap包
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
这两种方案,重新编译后运行都一切正常
总结
升级新版本好处多多,但是版本升级不要一下跨度太大。这样的话相关的包之间的引用就会产生一些版本不兼容的问题。
springcloudAlibaba设置allow-bean-definition-overriding=true不生效问题解决相关推荐
- Spring Boot: Bean definition overriding
在本文中,我将讨论棘手的Spring Boot bean定义覆盖机制. 为了使您对该主题更加清楚,让我们从小测验开始.请看下一个简单的例子. 因此,我们有2种配置,它们使用名称beanName实例化b ...
- Bean Definition到底是什么,附spring思维导图分享
写在前面的话&&About me 网上写spring的文章多如牛毛,为什么还要写呢,因为,很简单,那是人家写的:网上都鼓励你不要造轮子,为什么你还要造呢,因为,那不是你造的. 我不是要 ...
- Spring Cloud Stream报错:Invalid bean definition with name:bean definition with this name already exist
当想使用 Spring Cloud Stream 让微服务自己生产的消息自己消费时,如果使用的@Input("xxx")与@Output("xxx")注解中的& ...
- SpringBoot的Bean Definition 生成过程(源码分析)
1.目的: 从源码的角度分析整个springboot的启动流程.了解springboot项目在整个启动过程都干了一些什么. 因为spring项目的启动主要是分为两步,一个是bean definitio ...
- non-compatible bean definition of same name and class [com.echo.util.FileUploadDispatcher]
问题起因: 开发过程中更新代码 就报错了(整个项目运行不起来). 报错信息如下: Annotation-specified bean name 'fileUploadDispatcher' for b ...
- 使用elastic-job 发生Invalid bean definition with name异常
在springboot中使用elastic-job的时候项目启动异常: 2019-05-07 18:49:09.606 WARN 29958 --- [ main] ConfigServletWebS ...
- conflicts with existing, non-compatible bean definition of same name and class
Annotation-specified bean name 'xxxxxImpl' for bean class [cn.abc.dao.service.xxxxxImpl] conflicts w ...
- Invalid bean definition with name ‘dataSourceCSS‘ dfined in class path resource[xxx]
问题:Invalid bean definition with name 'dataSourceCSS' dfined in class path resource[aaa]:Could not re ...
- 运行web项目提示异常:non-compatible bean definition of same name and class【com.xxx.xxx.XXX】
情景描述:报错提示non-compatible bean definition of same name and class[com.xxx.xxx.XXX]但在代码中并未发现指定的bean有冲突 原 ...
最新文章
- POJ1195Mobile phones
- WinsockExpert+NC抓包上传之拿WEBSHELL
- anaconda的安装与使用详细教程
- puml绘制思维导图_思维导图的使用方法和技巧
- Leetcode950. Reveal Cards In Increasing Order按递增顺序显示卡牌
- PMP备考资料和备考经验分享(基于PMP第六版)
- linux ftp 服务配置
- Linux FTP 命令全集
- C语言中心对称图形定义,中心对称图形的定义
- 【爬虫实战】利用scrapy框架爬取豆瓣图书信息
- 怎样把mysql的多张表汇总成一张表_sql如何将多个表合并成一个表
- redis数据结构分析-redisObject-SDS
- mermaid与flowchart.js绘制流程图分支结构试验
- python语言判断中国节假日(pip install chinesecalendar)
- [前端框架]-VUE(上篇)
- 【模型训练】YOLOv7反光衣检测
- Python - 获取微信好友性别比例( Pie )
- 计算机科学与技术五行属什么,哪些八字特别适合互联网行业?
- 3主3从redis集群扩缩容配置案例说明
- matlab三维集装3D container箱装箱优化【matlab优化算法七】