解决Spring Boot应用整合Mybatis启动输出警告日志:
[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 依赖的自动配置导致的:
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
只需要在应用启动类加上注解 @MapperScan 即可,
@MapperScan({"io.github.yidasanqian.dao"})
public class ChannelApplication extends ProcessorApplication {
public static void main(String[] args) {
SpringApplication.run(ChannelApplication.class, args);
}
}
重要的是要指定扫描的mapper接口包路径,上面表示扫描包为io.github.yidasanqian.dao下的所有mapper接口定义。