This is an automated email from the ASF dual-hosted git repository.

jianbin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new b16f9cd519 bugfix: fix file.conf read failed after package (#6899)
b16f9cd519 is described below

commit b16f9cd5199b835a5450959e87cc21d7b504c0ea
Author: A Cabbage <[email protected]>
AuthorDate: Tue Oct 8 10:10:43 2024 +0800

    bugfix: fix file.conf read failed after package (#6899)
---
 changes/en-us/2.x.md                               |  4 +--
 changes/zh-cn/2.x.md                               |  3 +-
 .../org/apache/seata/config/FileConfiguration.java | 38 ++++++++++------------
 3 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 2dd147c01b..f6d8b97e19 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -8,7 +8,7 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#6881](https://github.com/apache/incubator-seata/pull/6881)]support grpc
 
 ### bugfix:
-
+- [[#6899](https://github.com/apache/incubator-seata/pull/6899)] fix file.conf 
read failed after package
 
 ### optimize:
 - [[#6826](https://github.com/apache/incubator-seata/pull/6826)] remove the 
branch registration operation of the XA read-only transaction
@@ -36,8 +36,8 @@ Thanks to these contributors for their code commits. Please 
report an unintended
 - [dk2k](https://github.com/dk2k)
 - [MaoMaoandSnail](https://github.com/MaoMaoandSnail)
 - [yougecn](https://github.com/yougecn)
+- [xjlgod](https://github.com/xjlgod)
 - [PleaseGiveMeTheCoke](https://github.com/PleaseGiveMeTheCoke)
 
 
-
 Also, we receive many valuable issues, questions and advices from our 
community. Thanks for you all.
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 624db67f90..6662c288c6 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -7,7 +7,7 @@
 [[#6881](https://github.com/apache/incubator-seata/pull/6881)]全链路支持grpc
 
 ### bugfix:
-
+- [[#6899](https://github.com/apache/incubator-seata/pull/6899)] 
修复file.conf打包后的读取
 
 ### optimize:
 - [[#6826](https://github.com/apache/incubator-seata/pull/6826)] 
移除只读XA事务的分支注册操作
@@ -36,6 +36,7 @@
 - [dk2k](https://github.com/dk2k)
 - [MaoMaoandSnail](https://github.com/MaoMaoandSnail)
 - [yougecn](https://github.com/yougecn)
+- [xjlgod](https://github.com/xjlgod)
 - [PleaseGiveMeTheCoke](https://github.com/PleaseGiveMeTheCoke)
 
 
diff --git 
a/config/seata-config-core/src/main/java/org/apache/seata/config/FileConfiguration.java
 
b/config/seata-config-core/src/main/java/org/apache/seata/config/FileConfiguration.java
index 8c775fe2c9..91b2a290c0 100644
--- 
a/config/seata-config-core/src/main/java/org/apache/seata/config/FileConfiguration.java
+++ 
b/config/seata-config-core/src/main/java/org/apache/seata/config/FileConfiguration.java
@@ -16,13 +16,22 @@
  */
 package org.apache.seata.config;
 
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.seata.common.thread.NamedThreadFactory;
+import org.apache.seata.common.util.CollectionUtils;
+import org.apache.seata.common.util.StringUtils;
+import org.apache.seata.config.ConfigFuture.ConfigOperation;
+import org.apache.seata.config.file.FileConfig;
+
 import java.io.File;
 import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -32,15 +41,8 @@ import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.seata.common.thread.NamedThreadFactory;
-import org.apache.seata.common.util.CollectionUtils;
-import org.apache.seata.common.util.StringUtils;
-import org.apache.seata.config.ConfigFuture.ConfigOperation;
-import org.apache.seata.config.file.FileConfig;
-import org.apache.commons.lang.ObjectUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 /**
  * The type FileConfiguration.
  *
@@ -134,7 +136,6 @@ public class FileConfiguration extends 
AbstractConfiguration {
             boolean filePathCustom = name.startsWith(SYS_FILE_RESOURCE_PREFIX);
             String filePath = filePathCustom ? 
name.substring(SYS_FILE_RESOURCE_PREFIX.length()) : name;
             String decodedPath = URLDecoder.decode(filePath, 
StandardCharsets.UTF_8.name());
-
             File targetFile = getFileFromFileSystem(decodedPath);
             if (targetFile != null) {
                 return targetFile;
@@ -157,21 +158,18 @@ public class FileConfiguration extends 
AbstractConfiguration {
 
         // run with jar file and not package third lib into jar file, 
this.getClass().getClassLoader() will be null
         URL resourceUrl = this.getClass().getClassLoader().getResource("");
-        String[] tryPaths = null;
+        // try to get log dir (spring.config.additional-location) after 
package and run sh or bat in bin dir
+        String configLocation = 
System.getProperty("spring.config.additional-location");
+        List<String> tryPathsList = new ArrayList<>();
+        tryPathsList.add(decodedPath);
         if (resourceUrl != null) {
-            tryPaths = new String[]{
-                // first: project dir
-                resourceUrl.getPath() + decodedPath,
-                // second: system path
-                decodedPath
-            };
-        } else {
-            tryPaths = new String[]{
-                decodedPath
-            };
+            tryPathsList.add(resourceUrl.getPath() + decodedPath);
+        }
+        if (configLocation != null) {
+            tryPathsList.add(configLocation + decodedPath);
         }
 
-
+        String[] tryPaths = tryPathsList.toArray(new String[0]);
         for (String tryPath : tryPaths) {
             File targetFile = new File(tryPath);
             if (targetFile.exists()) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to