SystemProperties.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package cn.com.qmth.examcloud.web.config;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import org.apache.commons.io.FileUtils;
  5. import org.apache.commons.lang3.StringUtils;
  6. import org.springframework.boot.context.properties.ConfigurationProperties;
  7. import org.springframework.stereotype.Component;
  8. import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
  9. import cn.com.qmth.examcloud.commons.util.PathUtil;
  10. import cn.com.qmth.examcloud.web.support.ClasspathHelper;
  11. /**
  12. * 系统配置
  13. *
  14. * @author WANGWEI
  15. * @date 2018年9月7日
  16. * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
  17. */
  18. @Component
  19. @ConfigurationProperties("examcloud.web.sys")
  20. public class SystemProperties {
  21. private String dataDir;
  22. private String tempDataDir;
  23. /**
  24. * 构造函数
  25. *
  26. */
  27. public SystemProperties() {
  28. if (StringUtils.isBlank(dataDir)) {
  29. String classpath = ClasspathHelper.getClasspath();
  30. String path = new File(classpath).getParent() + File.separator + "data";
  31. dataDir = PathUtil.getCanonicalPath(new File(path));
  32. }
  33. if (StringUtils.isBlank(tempDataDir)) {
  34. String classpath = ClasspathHelper.getClasspath();
  35. String path = new File(classpath).getParent() + File.separator + "temp";
  36. tempDataDir = PathUtil.getCanonicalPath(new File(path));
  37. }
  38. try {
  39. FileUtils.forceMkdir(new File(dataDir));
  40. } catch (IOException e) {
  41. throw new ExamCloudRuntimeException("fail to make data dir. path=" + dataDir);
  42. }
  43. try {
  44. FileUtils.forceMkdir(new File(tempDataDir));
  45. } catch (IOException e) {
  46. throw new ExamCloudRuntimeException("fail to make temp data dir. path=" + tempDataDir);
  47. }
  48. }
  49. public String getDataDir() {
  50. return dataDir;
  51. }
  52. public void setDataDir(String dataDir) {
  53. this.dataDir = dataDir;
  54. }
  55. public String getTempDataDir() {
  56. return tempDataDir;
  57. }
  58. public void setTempDataDir(String tempDataDir) {
  59. this.tempDataDir = tempDataDir;
  60. }
  61. }