123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package cn.com.qmth.examcloud.web.config;
- import java.io.File;
- import java.io.IOException;
- import org.apache.commons.io.FileUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.boot.context.properties.ConfigurationProperties;
- import org.springframework.stereotype.Component;
- import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
- import cn.com.qmth.examcloud.commons.util.PathUtil;
- import cn.com.qmth.examcloud.web.support.ClasspathHelper;
- /**
- * 系统配置
- *
- * @author WANGWEI
- * @date 2018年9月7日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
- @Component
- @ConfigurationProperties("examcloud.web.sys")
- public class SystemProperties {
- private String dataDir;
- private String tempDataDir;
- /**
- * 构造函数
- *
- */
- public SystemProperties() {
- if (StringUtils.isBlank(dataDir)) {
- String classpath = ClasspathHelper.getClasspath();
- String path = new File(classpath).getParent() + File.separator + "data";
- dataDir = PathUtil.getCanonicalPath(new File(path));
- }
- if (StringUtils.isBlank(tempDataDir)) {
- String classpath = ClasspathHelper.getClasspath();
- String path = new File(classpath).getParent() + File.separator + "temp";
- tempDataDir = PathUtil.getCanonicalPath(new File(path));
- }
- try {
- FileUtils.forceMkdir(new File(dataDir));
- } catch (IOException e) {
- throw new ExamCloudRuntimeException("fail to make data dir. path=" + dataDir);
- }
- try {
- FileUtils.forceMkdir(new File(tempDataDir));
- } catch (IOException e) {
- throw new ExamCloudRuntimeException("fail to make temp data dir. path=" + tempDataDir);
- }
- }
- public String getDataDir() {
- return dataDir;
- }
- public void setDataDir(String dataDir) {
- this.dataDir = dataDir;
- }
- public String getTempDataDir() {
- return tempDataDir;
- }
- public void setTempDataDir(String tempDataDir) {
- this.tempDataDir = tempDataDir;
- }
- }
|