解决WARN:Skipping MapperFactoryBean with name ‘xxxBeanMapper‘ and ‘com.xxx.xxxMapper‘ mapperInterface

问题描述

报错信息:Skipping MapperFactoryBean with name ‘xxxMapper’ and ‘xxx.xxx.xxx.mapper.xxxxxMapper’ nterface. Bean already defined with the same name!
若依项目启动时控制台打印出以下WARN 日志,Bean already defined with the same name日志信息大意就是Bean重复注入

 WARN  org.mybatis.spring.mapper.ClassPathMapperScanner - Skipping MapperFactoryBean with name 'archiveBeanMapper' and 'com.cxstar.business.repository.mapper.ArchiveBeanMapper' mapperInterface. Bean already defined with the same name! WARN  org.mybatis.spring.mapper.ClassPathMapperScanner - Skipping MapperFactoryBean with name 'badWordBeanMapper' and 'com.cxstar.business.repository.mapper.BadWordBeanMapper' mapperInterface. Bean already defined with the same name! WARN  org.mybatis.spring.mapper.ClassPathMapperScanner - Skipping MapperFactoryBean with name 'bookMapper' and 'com.cxstar.business.repository.mapper.BookMapper' mapperInterface. Bean already defined with the same name! WARN  org.mybatis.spring.mapper.ClassPathMapperScanner - Skipping MapperFactoryBean with name 'clcViewMapper' and 'com.cxstar.business.repository.mapper.ClcViewMapper' mapperInterface. Bean already defined with the same name! WARN  org.mybatis.spring.mapper.ClassPathMapperScanner - Skipping MapperFactoryBean with name 'ebookCollectionMapper' and 'com.cxstar.business.repository.mapper.EbookCollectionMapper' mapperInterface. Bean already defined with the same name! WARN  org.mybatis.spring.mapper.ClassPathMapperScanner - Skipping MapperFactoryBean with name 'ebookCollectionUnitMapper' and 'com.cxstar.business.repository.mapper.EbookCollectionUnitMapper' mapperInterface. Bean already defined with the same name! WARN  org.mybatis.spring.mapper.ClassPathMapperScanner - Skipping MapperFactoryBean with name 'esPushMapper' and 'com.cxstar.business.repository.mapper.EsPushMapper' mapperInterface. Bean already defined with the same name! 

问题分析

该问题目前还没有发现对项目有影响,但是希望排除掉该问题,因此需要排查问题原因
首先提示Bean重复注入,因此从注入Bean的地方开始排查
当前若依项目使用了自带的mybatis,以及后引入的mybatisplus,先排查这两的配置类的扫描文件是否有路径重复

Mybatis的配置类

/*** 程序注解配置*/
@Configuration
// 表示通过aop框架暴露该代理对象,AopContext能够访问
@EnableAspectJAutoProxy(exposeProxy = true)
// 指定要扫描的Mapper类的包的路径
@MapperScan("com.zqtest.**.mapper")
//@MapperScans({@MapperScan(value = "com.cxstar.system.mapper"),@MapperScan(value = "com.cxstar.quartz.mapper")})
public class ApplicationConfig {//...
}

MybatisPlus的配置类

@EnableTransactionManagement
@Configuration
@MapperScans({@MapperScan(value = "com.zqtest.**.repository.mapper")})
public class MybatisPlusConfig {//...
}

问题就在于Mybatis@MapperScan路径已经包含了MybatisPlus的@MapperScan路径,无论谁先被Spring实例化都会导致最后一个被实例化时报出bean重复注入的警告

问题解决

如果项目中同时使用了Mybatis和MybatisPlus,在各自配置类上应配置详细的要扫描的Mapper类的包的路径,而不是使用‘**’等导致扫描路径重复。
在这里插入图片描述


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部