diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md index 2dd147c01b5..f6d8b97e192 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 624db67f904..6662c288c6a 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 8c775fe2c93..91b2a290c04 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.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 @@ private File getConfigFile(String name) { 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 @@ private File getFileFromFileSystem(String decodedPath) { // 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 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()) {