按笔者 Spring Boot 2 实践记录之 MySQL + MyBatis 配置 中的方式,若是想正确运行,须要在 Mapper 类上添加 @Mapper 注解。html
可是加入此注解以后,启动时会出现以下警告:mybatis
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.
虽然不影响运行,可是对于追求完美的童鞋而言,倒是小有遗憾。app
两条信息各自对应了一个问题,逐条解决便可。less
第一个问题是由 Mapper 注解引发的,将其去掉。可是这样一来,第二个问题所指出的找不到 mapper 包的问题,就会引发 Mapper bean 找不到的问题。post
嗯,在配置中添加 Mapper 扫描的基础包便可,在配置类上方添加以下注解:url
@MapperScan(basePackages = "tk.mybatis.xxx.mapper")
完美解决!spa