From 8590bbf93343f5ae7fc5c3c7a0a525582af6e14c Mon Sep 17 00:00:00 2001 From: zhang siyu Date: Fri, 17 Dec 2021 10:53:18 +0800 Subject: [PATCH] bugfix: fix code for "sessionMode" not execute problem (#4213) --- changes/1.5.0.md | 1 + changes/en-us/1.5.0.md | 1 + .../io/seata/server/ServerApplicationListener.java | 13 +++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/changes/1.5.0.md b/changes/1.5.0.md index c8691fdd156..e2655fc94f9 100644 --- a/changes/1.5.0.md +++ b/changes/1.5.0.md @@ -38,6 +38,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单 - [[#3906](https://github.com/seata/seata/pull/3906)] 支持 SPI 卸载 - [[#3668](https://github.com/seata/seata/pull/3668)] 支持kotlin协程 - [[#4134](https://github.com/seata/seata/pull/4134)] 初始化控制台基础代码 + - [[#4213](https://github.com/seata/seata/pull/4213)] 修复部分"sessionMode"代码没执行导致启动失败问题 ### bugfix: diff --git a/changes/en-us/1.5.0.md b/changes/en-us/1.5.0.md index 476ce2468e6..f6c390d6c07 100644 --- a/changes/en-us/1.5.0.md +++ b/changes/en-us/1.5.0.md @@ -76,6 +76,7 @@ - [[#4177](https://github.com/seata/seata/pull/4177)] fix the problem of accidentally releasing the global lock - [[#4174](https://github.com/seata/seata/pull/4174)] fix delete undo log connection already closed - [[#4189](https://github.com/seata/seata/pull/4189)] fix the `kafka-appender.xml` and `logstash-appender.xml` + - [[#4213](https://github.com/seata/seata/pull/4213)] fix code for "sessionMode" not execute problem ### optimize: diff --git a/server/src/main/java/io/seata/server/ServerApplicationListener.java b/server/src/main/java/io/seata/server/ServerApplicationListener.java index 1ba53e9656e..ea71eb43b03 100644 --- a/server/src/main/java/io/seata/server/ServerApplicationListener.java +++ b/server/src/main/java/io/seata/server/ServerApplicationListener.java @@ -54,6 +54,13 @@ public void onApplicationEvent(ApplicationEvent event) { ApplicationEnvironmentPreparedEvent environmentPreparedEvent = (ApplicationEnvironmentPreparedEvent)event; ConfigurableEnvironment environment = environmentPreparedEvent.getEnvironment(); + + // Load by priority + System.setProperty("sessionMode", + environment.getProperty(SERVER_STORE_SESSION_MODE, environmentPreparedEvent.getEnvironment().getProperty(SERVER_STORE_MODE, "file"))); + System.setProperty("lockMode", + environment.getProperty(SERVER_STORE_LOCK_MODE, environmentPreparedEvent.getEnvironment().getProperty(SERVER_STORE_MODE, "file"))); + String[] args = environmentPreparedEvent.getArgs(); // port: -h > -D > env > yml > default @@ -96,12 +103,6 @@ public void onApplicationEvent(ApplicationEvent event) { } String servicePort = String.valueOf(Integer.parseInt(serverPort) + SERVICE_OFFSET_SPRING_BOOT); setTargetPort(environment, servicePort, true); - - // Load by priority - System.setProperty("sessionMode", - environment.getProperty(SERVER_STORE_SESSION_MODE, environmentPreparedEvent.getEnvironment().getProperty(SERVER_STORE_MODE, "file"))); - System.setProperty("lockMode", - environment.getProperty(SERVER_STORE_LOCK_MODE, environmentPreparedEvent.getEnvironment().getProperty(SERVER_STORE_MODE, "file"))); } private void setTargetPort(ConfigurableEnvironment environment, String port, boolean needAddPropertySource) {