Skipping MapperFactoryBean with name ‘xxxMapper' mapperInterface

解决Spring Boot应用整合Mybatis启动输出警告日志:

1
[main] o.m.s.mapper.ClassPathMapperScanner - Skipping MapperFactoryBean with name 'channelMapper' and 'io.github.yidasanqian.dao.ChannelMapper' mapperInterface. Bean already defined with the same name!

这是由于mybatis-spring-boot-starter 依赖的自动配置导致的:

1
2
3
4
5
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>

只需要在应用启动类加上注解 @MapperScan 即可,

1
2
3
4
5
6
7
@MapperScan({"io.github.yidasanqian.dao"})
@SpringCloudApplication
public class ChannelApplication {
public static void main(String[] args) {
SpringApplication.run(ChannelApplication.class, args);
}
}

重要的是要指定扫描的mapper接口包路径,上面表示扫描包为io.github.yidasanqian.dao下的所有mapper接口定义。

以上,如有问题欢迎提出!

如果对您有所帮助,欢迎投食!
0%