Skip to content

Commit 949ef86

Browse files
YunaiVgitee-org
authored andcommitted
!208 使用外部中间件时,如:金蝶、东方通 在不重启整个中间件的情况下,二次部署或多个服务同时部署在一个虚拟机下(JVM) IdTypeEnvir…
Merge pull request !208 from 墨轩/master
2 parents 2a6b685 + 17f8047 commit 949ef86

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/IdTypeEnvironmentPostProcessor.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
import org.springframework.boot.SpringApplication;
1010
import org.springframework.boot.env.EnvironmentPostProcessor;
1111
import org.springframework.core.env.ConfigurableEnvironment;
12+
import org.springframework.core.env.MapPropertySource;
1213

14+
import java.util.HashMap;
15+
import java.util.Map;
1316
import java.util.Set;
1417

1518
/**
@@ -56,11 +59,19 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp
5659
}
5760

5861
public IdType getIdType(ConfigurableEnvironment environment) {
59-
return environment.getProperty(ID_TYPE_KEY, IdType.class);
62+
String value = environment.getProperty(ID_TYPE_KEY);
63+
try {
64+
return StrUtil.isNotBlank(value) ? IdType.valueOf(value) : IdType.NONE;
65+
} catch (IllegalArgumentException ex) {
66+
log.error("[getIdType][无法解析 id-type 配置值({})]", value, ex)
67+
return IdType.NONE;
68+
}
6069
}
6170

6271
public void setIdType(ConfigurableEnvironment environment, IdType idType) {
63-
environment.getSystemProperties().put(ID_TYPE_KEY, idType);
72+
Map<String, Object> map = new HashMap<>();
73+
map.put(ID_TYPE_KEY, idType);
74+
environment.getPropertySources().addFirst(new MapPropertySource("mybatisPlusIdType", map));
6475
log.info("[setIdType][修改 MyBatis Plus 的 idType 为({})]", idType);
6576
}
6677

0 commit comments

Comments
 (0)