|
|
@@ -1,7 +1,9 @@
|
|
|
package com.ruoyi.common.config;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.ResourceUtils;
|
|
|
|
|
|
/**
|
|
|
* 读取项目相关配置
|
|
|
@@ -67,7 +69,28 @@ public class RuoYiConfig
|
|
|
|
|
|
public void setProfile(String profile)
|
|
|
{
|
|
|
- RuoYiConfig.profile = profile;
|
|
|
+ if (!profile.startsWith("/")) {
|
|
|
+ try {
|
|
|
+ String rootPath = null;
|
|
|
+ try {
|
|
|
+ File classpathFile = ResourceUtils.getFile("classpath:");
|
|
|
+ rootPath = classpathFile.getParentFile().getParentFile().getAbsolutePath();
|
|
|
+ } catch (Exception e) {
|
|
|
+ rootPath = System.getProperty("user.dir");
|
|
|
+ if (rootPath.endsWith("target")) {
|
|
|
+ rootPath = new File(rootPath).getParent();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RuoYiConfig.profile = rootPath + File.separator + profile;
|
|
|
+ System.out.println("[RuoYiConfig] 相对路径转换为绝对路径: " + profile + " -> " + RuoYiConfig.profile);
|
|
|
+ } catch (Exception e) {
|
|
|
+ RuoYiConfig.profile = profile;
|
|
|
+ System.out.println("[RuoYiConfig] 获取根目录失败,使用原始路径: " + profile);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ RuoYiConfig.profile = profile;
|
|
|
+ System.out.println("[RuoYiConfig] 使用绝对路径: " + profile);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static boolean isAddressEnabled()
|