Commit 6d057b8d4daf69b30498c447d56bfe431c0f82a4
1 parent
95355cb5
!208 使用外部中间件时,如:金蝶、东方通 在不重启整个中间件的情况下,二次部署或多个服务同时部署在一个虚拟机下(JVM) IdTypeEnvir…
Showing
1 changed file
with
13 additions
and
2 deletions
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/IdTypeEnvironmentPostProcessor.java
| @@ -9,7 +9,10 @@ import lombok.extern.slf4j.Slf4j; | @@ -9,7 +9,10 @@ import lombok.extern.slf4j.Slf4j; | ||
| 9 | import org.springframework.boot.SpringApplication; | 9 | import org.springframework.boot.SpringApplication; |
| 10 | import org.springframework.boot.env.EnvironmentPostProcessor; | 10 | import org.springframework.boot.env.EnvironmentPostProcessor; |
| 11 | import org.springframework.core.env.ConfigurableEnvironment; | 11 | import org.springframework.core.env.ConfigurableEnvironment; |
| 12 | +import org.springframework.core.env.MapPropertySource; | ||
| 12 | 13 | ||
| 14 | +import java.util.HashMap; | ||
| 15 | +import java.util.Map; | ||
| 13 | import java.util.Set; | 16 | import java.util.Set; |
| 14 | 17 | ||
| 15 | /** | 18 | /** |
| @@ -56,11 +59,19 @@ public class IdTypeEnvironmentPostProcessor implements EnvironmentPostProcessor | @@ -56,11 +59,19 @@ public class IdTypeEnvironmentPostProcessor implements EnvironmentPostProcessor | ||
| 56 | } | 59 | } |
| 57 | 60 | ||
| 58 | public IdType getIdType(ConfigurableEnvironment environment) { | 61 | 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 | + } | ||
| 60 | } | 69 | } |
| 61 | 70 | ||
| 62 | public void setIdType(ConfigurableEnvironment environment, IdType idType) { | 71 | 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)); | ||
| 64 | log.info("[setIdType][修改 MyBatis Plus 的 idType 为({})]", idType); | 75 | log.info("[setIdType][修改 MyBatis Plus 的 idType 为({})]", idType); |
| 65 | } | 76 | } |
| 66 | 77 |