Skip to content

Commit c116841

Browse files
committed
更新Spring DevTools 配置
1 parent b4aec3c commit c116841

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@
2626
<version>1.1.0</version>
2727
</dependency>
2828
```
29+
## Spring DevTools 配置
30+
感谢[emf1002](https://github.com/emf1002)提供的解决方案。
31+
32+
在使用 DevTools 时,通用Mapper经常会出现 class x.x.A cannot be cast to x.x.A。
33+
34+
同一个类如果使用了不同的类加载器,就会产生这样的错误,所以解决方案就是让通用Mapper和实体类使用相同的类加载器即可。
35+
36+
DevTools 默认会对 IDE 中引入的所有项目使用 restart 类加载器,对于引入的 jar 包使用 base 类加载器,因此只要保证通用Mapper的jar包使用 restart
37+
类加载器即可。
38+
39+
`src/main/resources` 中创建 META-INF 目录,在此目录下添加 spring-devtools.properties 配置,内容如下:
40+
```properties
41+
restart.include.mapper=/mapper-[\\w-\\.]+jar
42+
restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar
43+
```
44+
使用这个配置后,就会使用 restart 类加载加载 include 进去的 jar 包。
2945

3046
## 集成 MyBatis Generator
3147
通过 Maven 插件集成的,所以运行插件使用下面的命令:
@@ -75,7 +91,6 @@ pagehelper:
7591
params: count=countSql
7692
```
7793
78-
7994
注意 mapper 配置,因为参数名固定,所以接收参数使用的对象,按照 Spring Boot 配置规则,大写字母都变了带横线的小写字母。针对如 IDENTITY(对应i-d-e-n-t-i-t-y)提供了全小写的 identity 配置,如果 IDE 能自动提示,看自动提示即可。
8095
8196
## SSM集成的基础项目

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<groupId>org.springframework.boot</groupId>
4141
<artifactId>spring-boot-starter-test</artifactId>
4242
</dependency>
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-devtools</artifactId>
46+
<optional>true</optional>
47+
</dependency>
4348

4449
<dependency>
4550
<groupId>mysql</groupId>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
restart.include.mapper=/mapper-[\\w-\\.]+jar
2+
restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar

0 commit comments

Comments
 (0)