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

This commit is contained in:
junjun
2024-12-26 11:23:52 +08:00
committed by fit2cloud-chenyw
parent 5f36f8d67e
commit 11ec63d5c9

View File

@@ -17,11 +17,14 @@ public class ConfigUtils {
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");
// Resource resource = new FileSystemResource("D:\\dataease\\electron\\dataease-desktop\\resources\\config\\application.yml");
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(resource);
String basePath = Objects.requireNonNull(factory.getObject()).getProperty("base-path", "");
basePath = basePath.replaceAll("\\$\\{user.home}", System.getProperty("user.home").replaceAll("\\\\", "/"));
String property = Objects.requireNonNull(factory.getObject()).getProperty(key, defaultValue);
return property.replaceAll("\\$\\{user.home}", System.getProperty("user.home").replaceAll("\\\\", "/"));
return property.replaceAll("\\$\\{base-path}", basePath);
} catch (Exception e) {
}
return defaultValue;