chore: 将资源的固定路径优化为可读取yml配置中的路径

This commit is contained in:
junjun
2024-12-31 12:36:46 +08:00
committed by xuwei-fit2cloud
parent 37a7eb4c10
commit be19a11c8c

View File

@@ -12,11 +12,13 @@ import java.util.Objects;
*/
public class ConfigUtils {
public static String configPath = "opt" + File.separator + "dataease2.0" + File.separator + "config" + File.separator + "application.yml";
public static String getConfig(String key, String defaultValue) {
try {
String filePath = System.getProperty("user.dir");
filePath = filePath.replace("file:", "").substring(0, filePath.lastIndexOf("resources"));
Resource resource = new FileSystemResource(filePath + "resources" + File.separator + "config" + File.separator + "application.yml");
String filePath = System.getProperty("user.home");
filePath = filePath.replace("file:", "");
Resource resource = new FileSystemResource(filePath + File.separator + configPath);
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(resource);