解决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类的包的路径,而不是使用‘**’等导致扫描路径重复。
在这里插入图片描述

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐州蔡徐坤

又要到饭了兄弟们

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值