引入tk mybaits报错

一个老项目的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 <dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>4.1.4</version>
</dependency>

重构成springboot

修改配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
<!--spring-boot mybatis依赖-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!--添加tk-mapper依赖-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>

启动类, 注意这里的 MapperScan 引入应该需要引入 tk.mybatis.spring.annotation.MapperScan

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import tk.mybatis.spring.annotation.MapperScan;

@MapperScan(basePackages = "com.coder.mapper")
@SpringBootApplication
public class BackendApplication {

public static void main(String[] args) {
SpringApplication.run(BackendApplication.class, args);
}

}

参考:


引入tk mybaits报错
https://xiamu.icu/Java/引入tk mybatis报错/
作者
肉豆蔻吖
发布于
2023年11月19日
许可协议