org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean

本文深入探讨了在使用MyBatis时,如何解决由Mapper类与Spring框架中MapperFactoryBean定义冲突导致的问题。通过分析mybatis初始化流程,揭示了问题本质,并提供了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天写工具方法在,在一个被其他工程依赖的项目里加了一个dao类,其它依赖项目报错

org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'hqAuthMapperExt' for bean class [com.hunqingplatform.hunqing.dao.mapper1.ext.td.HqAuthMapperExt] conflicts with existing, non-compatible bean definition of same name and class [org.mybatis.spring.mapper.MapperFactoryBean]

刚看到则异常感觉有点奇怪,bean的name怎么可能跟MapperFactoryBean类加载冲突呢,看了下mybatis的初始化流程,在ClassPathMapperScanner读取beanDefinition之后会把beanClass属性设置为MapperFactoryBean,而name还是dao的name,这就是FactoryBean的,在自动注入时通过判断beanClass类型为MapperFactoryBean工厂bean在AbstractBeanFactory的getObjectForBeanInstance方法里判断如果是工厂bean则调用factoryBean的getobject方法获取实际bean实例

 

  

ERROR 2025-07-25 13:51:42.114 172.18.18.95 org.springframework.boot.SpringApplication - Application startup failed org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.viewhigh.vadp.framework.web.Application]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'dynDesCore_ReceiptPoolBOImpl_bo' for bean class [com.viewhigh.oes.dyndes.dyndescore.bo.impl.ReceiptPoolBOImpl] conflicts with existing, non-compatible bean definition of same name and class [com.viewhigh.oes.custom.dyncustom.bo.impl.ReceiptPoolBOImpl] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:183) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) at org.springframe
最新发布
07-26
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值