出現這個錯誤是通用Mapper初始化的錯誤,排查的方向就是往這個方向,可能的情況有以下幾種:
1.jar包衝突
<dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>3.3.9</version> </dependency> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency>
如圖所示這裏有兩個tk.mybatis通用Mapper的包了,所以springboot不知道該初始化哪個
<dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency>
這裏使用這個包,重啓後運行正常
2,MapperCan 掃包配置錯誤
@SpringBootApplication @MapperScan(basePackages = "com.example.demo.*.dao") @ComponentScan("com.example.demo.*") public class DemoApplication extends SpringBootServletInitializer{
之前配置的是
@MapperScan(basePackages = "com.example.demo.*.dao")
應該改成
@MapperScan(basePackages = "com.example.demo.*.dao.*")
我思考了以下應該是掃包的話是掃很多個包,所以應該是以*結尾的
這樣重啓後正常