Spring Boot 2 实践记录之 MyBatis 集成的启动时警告信息问题

按笔者 Spring Boot 2 实践记录之 MySQL + MyBatis 配置 中的方式,如果想正确运行,需要在 Mapper 类上添加 @Mapper 注解。

但是加入此注解之后,启动时会出现如下警告:

Skipping MapperFactoryBean with name 'xxxMapper' and 'tk.mybatis.xxx.mapper.xxxMapper' mapperInterface. Bean already defined with the same name!
No MyBatis mapper was found in '[tk.mybatis]' package. Please check your configuration.

虽然不影响运行,但是对于追求完美的童鞋而言,却是小有遗憾。

两条信息各自对应了一个问题,逐条解决即可。

第一个问题是由 Mapper 注解引起的,将其去掉。但是这样一来,第二个问题所指出的找不到 mapper 包的问题,就会引起 Mapper bean 找不到的问题。

嗯,在配置中添加 Mapper 扫描的基础包即可,在配置类上方添加如下注解:

@MapperScan(basePackages = "tk.mybatis.xxx.mapper")

完美解决!

原文地址:https://www.cnblogs.com/matchless/p/10410534.html