今天写工具方法在,在一个被其他工程依赖的项目里加了一个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实例