ConflictingBeanDefinitionException: Annotation-specified bean name ‘XXX‘ for bean class

Spring Boot应用中的Conflicting Bean Definition异常分析与解决策略 解决项目启动报错Annotation-specified bean name ‘xxx‘问题 阅读详情

报错信息

Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'mybatisInterceptor' for bean class [com.sinandata.service.commons.config.MybatisInterceptor] conflicts with existing, non-compatible bean definition of same name and class [com.sinandata.kg.report.config.MybatisInterceptor]
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:349)
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:287)
	at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:296)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:207)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:175)

这个错误是因为在 Spring context 中有两个名称相同但类不兼容的 bean 定义而引起的。在您的项目中,有两个 XXX类被定义,并且都使用了相同的 bean 名称XXX,这导致了冲突。

如果该两个Bean都是你自己定义的,可以通过以下几种方式解决:

  1. 修改 bean 名称 - 将其中一个 MybatisInterceptor 的 bean 名称修改为不同的名称,避免名称冲突。

  2. 区分类名或包名 - 将两个 MybatisInterceptor 类的类名或所在包名进行区分,以避免类名冲突。

  3. 使用 @Qualifier 注解 - 在注入 bean 的过程中,使用 @Qualifier 注解指定要注入的具体 bean,而不是使用默认名称。例如:@Autowired @Qualifier(“mybatisInterceptor1”) private MybatisInterceptor mybatisInterceptor;

 如果其中一个是外部Jar包自带的依赖Bean,则通过以下方式排除Bean:
在启动类上加上注解
@ComponentScan( excludeFilters = [ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = [MybatisInterceptor.class()])])

解释:
 在 Spring 框架中,@ComponentScan 注解用于搜索标有 @Component、@Service、@Controller、@Repository 等注解的类,并将它们注册为 Spring 容器中的 Bean。有时候,您可能希望排除某些类,比如第三方库的类或者框架自带的类,以避免造成冲突。

 excludeFilters 属性是 @ComponentScan 注解的一个元素,可以用来指定要排除的类。其中,Filter 是一个枚举类型,包含四个过滤器类型:ANNOTATION、ASSIGNABLE_TYPE、ASPECTJ 和 CUSTOM。

 在提供的代码中,excludeFilters 属性使用了 ASSIGNABLE_TYPE 类型的过滤器,并指定了一个名为 MybatisInterceptor 的类。这意味着,如果某个类和 MybatisInterceptor 类型相同,它将被排除在扫描范围外,不会被注册为 Spring 容器中的 Bean。

【异常】ConflictingBeanDefinitionException: Annotation-specified bean name ‘voiceSettingMapper‘ for bean 具体来说,在项目中,有一个名为voiceSettingMapper的bean定义,这个bean的类是com.xxx.mapper.VoiceSettingMapper。但同时,Spring还试图创建另一个同名的bean,其类是org.mybatis.spring.mapper.MapperFactoryBean。如果你有两个同名的bean,但其中一个是你优先想使用的,你可以在那个bean上使用@Primary注解。为了解决这个问题,你有以下几种选择,请根据你的具体需求选择最适合的解决方案。 阅读详情

相关推荐

Power BI应用案例:淘宝用户行为分析实战

一、案例背景 基于千万级的淘宝用户的使用记录,对淘宝用户的行为进行分析,具体指标包括:日PV、日UV、小时PV、小时UV、不同用户行为的PV、用户购买次数分布、用户购买频次分布、活跃用户消费情况等。通过本案例,可以基本看看Power BI都能分析达到怎么样的效果。 二、数据来源及结构 阿里天池官方发布的1万用户在2014年双十二期间的行为记录,数据量达1200万+。 数据下载地址:...

灰哥数据智能的专栏 1万+

SpringBoot项目启动失败报错Annotation-specified bean name ‘xx‘ for bean class [xxx] conflicts with existing

问题描述 SpringBoot项目,更改醒目内容之后启动报错 Annotation-specified bean name ‘xx’ for bean class [xxx] conflicts with existing, non-compatible bean definition of same name and class[xxx] 问题分析 正在做的工作是将之前旧的项目进行功能拆分的微服务,导致其中一个部分在更新目录结构的过程中出现了工程中不同文件夹中复制了多分旧的工程的同一个文件的类,导致这

Mak1sΔe的博客 8万+

深度学习优化算法解析(Momentum, RMSProp, Adam)

之前看了很多人介绍网络的优化器optimizer,无奈很多都把简单的东西讲的复杂化了,不容易让人懂,恰好之前看过吴恩达老师的最新的课程,这里结合老师讲的和个人想法写一下,方便别人同时也为自己以后回顾吧。 深度学习的优化算法主要有GD,SGD,Momentum,RMSProp和Adam算法吧,还有诸如Adagrad算法,不过大同小异,理解了前面几个,后面的也就引刃而解了。GD算法,SGD算法以及m

willduan的博客 12万+

Failed to parse configuration ... ConflictingBeanDefinitionException: Annotation-specified bean name

Failed to parse configuration class conflicts with existing, non-compatible bean definition of same name and class 类名

test 8576

京东技术产品经理面试全记录:从简历投递到一面45分钟实战复盘

本文深度复盘京东技术产品经理面试全流程,从策略准备、思维题拆解、项目阐述到反问谈判,提供了一套可演练的求职策略体系。文章强调该岗位需具备横跨技术与商业的枢纽能力,并通过“QQ分组vs微信标签”等案例,剖析了产品思维与结构化表达在面试中的关键作用,助力候选人将紧张转化为掌控感。

weixin_29275257的博客 628

富士SC2022,C325,C328打印机扫描到网络详细教程

富士打印机SC2022,C328,C325等型号扫描到电脑教程

weixin_41926602的博客 1万+

ConflictingBeanDefinitionException异常,Annotation-specified bean name ‘redisConfig‘ for bean class

项目在启动的时候会报错: Annotation-specified bean name ‘xx’ for bean class [xxx] conflicts with existing, non-compatible bean definition of same name and class[xxx] 原因: spring中有相同名称的类时,使用时没有明确指定bean名称,则会抛出异常: 最简单的方法: 在项目中查找重复的Bean名称,将部分重复的bean名称更改一下;更改原则是:公共包下面的Bean保

qq_35146059的博客 4602

麻辣香锅病毒分析

Spicy Hot Pot浏览器劫持病毒(麻辣香锅病毒)从2020年初被安全公司监测到,因其病毒模块带有MLXG_KM被安全行业代称麻辣香锅病毒。目前通过各种激活工具传播, 包括暴风激活、小马激活和KMS激活等诸多工具,疑似与下载站进行合作推广此类激活工具。Spicy Hot Pot 是一个浏览器劫持 Rootkit,它会将用户的主页更改为指向恶意软件操作员控制的页面,此外还会将内存转储从机器上传到预定义的服务器,并结合本地更新功能以确保其保持更新。通常浏览器劫持者会通过更改用户主页的恶意可执行文件或注册表

不忘初心,护天下安全! 4787

Java:启动报错:ConflictingBeanDefinitionException: Annotation-specified bean name ‘xxx‘ for be [xxx] ...

Java:启动报错:ConflictingBeanDefinitionException: Annotation-specified bean name 'xxx' for be [xxx] conflicts with existing, non-compatible bean definition of same name and class [tk.mybatis.spring.mapper.MapperFactoryBean]

weixin_52116015的博客 529

硬件电路设计采集电路

摘要:采集电路是硬件设计中连接物理世界与数字系统的关键环节,主要用于将温度、压力等物理量转换为电信号。常见的采集电路包括模拟量采集(如温度、电压)、数字量采集(如开关状态)和特殊信号采集(如光、声音)。设计时需重点关注传感器选型、信号调理、电源接地、抗干扰和ADC配置等核心要素,确保信号链路的完整性和稳定性。合理的电路设计需结合具体应用场景,通过仿真和测试验证性能,最终实现精确可靠的数据采集。

qq_37999850的博客 1796

PCL 动态半径滤波【2025最新版】

使用PCL实现的2022年最新SCI论文——【Design of Dust-Filtering Algorithms for LiDAR Sensors Using Intensity and Range Information in Off-Road Vehicles】 一文中提出用于自动驾驶点云剔除粉尘、雨雪等影响因素导致的噪声点滤波算法。

点云侠的博客 1471

ConflictingBeanDefinitionException异常解决

org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'exceptionHandlerAdvice' for bean class [com.xxx.o2o.exceptionHandlerAdvice] conflicts with existing, non-compatible bean definition of same name and

weixin_45733659的博客 8736

1、JMP脚本编程全面指南:从基础到高级应用

本博客全面介绍了JMP脚本编程的各个方面,从JMP基础和JSL入门,到数据类型、数据结构、编程方法、数据表操作、图形与三维场景脚本,再到应用程序创建与扩展功能。内容涵盖脚本工具使用、常见任务实现、兼容性说明及未来发展趋势,旨在帮助用户掌握JMP脚本语言的强大功能,提升数据分析的自动化与定制化能力。适合从初学者到高级用户的深入学习与实践参考。

flink9streamer的博客 266

Spring Bean名称重复 ConflictingBeanDefinitionException 解决

冲突分析 如果我们希望将相同名称的类放入spring中时,如果未指定bean名称,则会抛出异常: Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'xxxx' for bean class [xxx] con...

AI天才研究院 2万+

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

团队协作中如何处理ConflictingBeanDefinitionException异常

当使用Spring框架进行Java应用程序开发时,可能会遇到ConflictingBeanDefinitionException异常。如:这个异常通常发生在以下情况下:在应用程序上下文中存在多个相同名称的Bean定义,导致Spring无法确定应该使用哪一个Bean。这个问题可能出现在团队协作开发中,特别是当不同的开发者在不同的模块中定义了相同名称的Bean时。在本文中,我们将探讨这个异常出现的原因、解决方案以及在团队协作开发中的编码建议。

FirstMrRight的博客 2241

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Spring启动异常之ConflictingBeanDefinitionException: Annotation-specified bean name ‘XXXXXService‘

启动Spring项目报错ConflictingBeanDefinitionException Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'XXXXXService' for bean class [com.service.common.MgrFileService] conflicts with existing.

MieMieFly的专栏 1万+

记录一个SpringBoot启动报错 Annotation-specified bean name ‘xxx‘的问题解决,简单排查思路

记录一个SpringBoot启动报错 Annotation-specified bean name 'xxx'的问题解决,简单排查思路

qq_45904119的博客 5273

Annotation-specified bean name ‘xxxController‘ for bean class [] conflicts with existing non-compati

Spring中很多注解都会有一个的参数,可以修改该参数值,来修改加载Spring中该类的bean的名称!但是,在之后需要注入该bean实例时候,则同样需要指定该bean的名称来注入!!!

m0_62780794的博客 2157

ConflictingBeanDefinitionException异常快速处理

简单理解为项目中存在两个名字相同的 Bean ,这两个Bean可能是代码里的,你可以通过全局搜索找到它们并改变名称;全局搜索找不到就说明是在你引入的jar包里,这时处理方式是在程序入口中用@ComponentScan注解来排除掉其中一个,参考如下。

kungFuApe的博客 1942

【莫名的BUG】

在同一个 Spring 应用上下文中存在两个不同包下的 某某 类,但它们都被配置为同一个 bean 名称 。Spring 容器无法区分这两个类,因此抛出ConflictingBeanDefinitionException 异常。

qq_45176189的博客 3093

Annotation-specified bean name.. for bean class ...

clean一下,再运行。 可能是idea缓存没清理,依然是上次的,导致报类名重复的错。

qq_42014105的博客 8237

Annotation-specified bean name for bean class

1、发现BUG:bug详情 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'f

心若向阳 无谓悲伤 2万+

Annotation-specified bean name 'xxx' for bean class [com.xxx.xxx.xxx] conflicts with existing

Annotation-specified bean name ‘userMapper’ for bean class [com.promote.website.mapper.UserMapper] conflicts with existing, non-compatible bean definition of same name and class [com.promote.user.mapp...

promote的博客 9981
上一篇: 用Spring Boot轻松实现定时任务--原理详解
下一篇: 解析SpringBoot中@Autowire注解的实现原理
JavaWizard-M
博客等级 码龄6年 3159粉丝 148原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值