wangwei 5 ani în urmă
părinte
comite
fbc4a03b80

+ 26 - 0
src/main/java/cn/com/qmth/examcloud/web/config/SystemConfig.java

@@ -1,8 +1,14 @@
 package cn.com.qmth.examcloud.web.config;
 
+import java.io.File;
+
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.stereotype.Component;
 
+import cn.com.qmth.examcloud.commons.util.PathUtil;
+import cn.com.qmth.examcloud.web.support.ClasspathHelper;
+
 /**
  * 系统配置
  *
@@ -18,6 +24,26 @@ public class SystemConfig {
 
 	private String tempDataDir;
 
+	/**
+	 * 构造函数
+	 *
+	 */
+	public SystemConfig() {
+
+		String classpath = ClasspathHelper.getClasspath();
+
+		if (StringUtils.isBlank(dataDir)) {
+			String path = new File(classpath).getParent() + File.separator + "data";
+			dataDir = PathUtil.getCanonicalPath(new File(path));
+		}
+
+		if (StringUtils.isBlank(tempDataDir)) {
+			String path = new File(classpath).getParent() + File.separator + "temp";
+			tempDataDir = PathUtil.getCanonicalPath(new File(path));
+		}
+
+	}
+
 	public String getDataDir() {
 		return dataDir;
 	}

+ 28 - 0
src/main/java/cn/com/qmth/examcloud/web/support/ClasspathHelper.java

@@ -0,0 +1,28 @@
+package cn.com.qmth.examcloud.web.support;
+
+import cn.com.qmth.examcloud.commons.util.PathUtil;
+
+/**
+ * classpath 定位
+ *
+ * @author WANGWEI
+ * @date 2019年11月8日
+ * @Copyright (c) 2018-? WANGWEI [QQ:522080330] All Rights Reserved.
+ */
+public class ClasspathHelper {
+
+	private static final String LOCATION_FILE = "classpath.location";
+
+	/**
+	 * 获取classpath
+	 *
+	 * @author WANGWEI
+	 * @return
+	 */
+	public static String getClasspath() {
+		String location = PathUtil.getResoucePath(LOCATION_FILE);
+		String classPath = location.substring(0, location.lastIndexOf(LOCATION_FILE));
+		return classPath;
+	}
+
+}