From e601b323ffdaeb8f626bfef85f03344e87cd7b21 Mon Sep 17 00:00:00 2001 From: wentao Date: Sun, 14 Jan 2018 02:17:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DPropertiesConfigureLoader?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=AF=BB=E5=8F=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/impl/PropertiesConfigureLoader.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nutzboot-core/src/main/java/org/nutz/boot/config/impl/PropertiesConfigureLoader.java b/nutzboot-core/src/main/java/org/nutz/boot/config/impl/PropertiesConfigureLoader.java index 8d7e2f94..dbde8b56 100644 --- a/nutzboot-core/src/main/java/org/nutz/boot/config/impl/PropertiesConfigureLoader.java +++ b/nutzboot-core/src/main/java/org/nutz/boot/config/impl/PropertiesConfigureLoader.java @@ -1,13 +1,14 @@ package org.nutz.boot.config.impl; +import org.nutz.ioc.impl.PropertiesProxy; +import org.nutz.lang.Lang; +import org.nutz.lang.Streams; + import java.io.File; import java.io.FileInputStream; import java.io.InputStream; -import java.util.ArrayList; import java.io.UnsupportedEncodingException; - -import org.nutz.ioc.impl.PropertiesProxy; -import org.nutz.lang.Streams; +import java.util.ArrayList; /** * 配置信息优先级, 从低到高:

@@ -20,7 +21,10 @@ public class PropertiesConfigureLoader extends AbstractConfigureLoader { // 获取应用程序绝对路径 private static String getBasePath() { - String basePath = PropertiesConfigureLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + // 获取mainClass,参照AppContext调试分析,Thread.currentThread().getStackTrace()的最后一个元素就是主方法 + String basePath = ""; + StackTraceElement[] ts = Thread.currentThread().getStackTrace(); + basePath = Lang.loadClassQuite(ts[ts.length-1].getClassName()).getProtectionDomain().getCodeSource().getLocation().getPath(); int lastIndex = basePath.lastIndexOf(File.separator); basePath = basePath.substring(0, lastIndex); try {