xiatian %!s(int64=4) %!d(string=hai) anos
pai
achega
c388a6ed2d

+ 44 - 29
themis-backend/src/main/java/com/qmth/themis/backend/ThemisBackendApplication.java

@@ -1,7 +1,9 @@
 package com.qmth.themis.backend;
 
-import com.qmth.themis.backend.config.DictionaryConfig;
-import com.qmth.themis.common.contanst.Constants;
+import java.io.File;
+
+import javax.annotation.Resource;
+
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -14,40 +16,53 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 import org.springframework.web.multipart.MultipartResolver;
 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
 
-import javax.annotation.Resource;
+import com.qmth.themis.backend.config.DictionaryConfig;
+import com.qmth.themis.business.config.SystemConfig;
+import com.qmth.themis.business.constant.SpringContextHolder;
+import com.qmth.themis.common.contanst.Constants;
 
 //import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
 
 @SpringBootApplication
-@ComponentScan(basePackages = {"com.qmth.themis"})
+@ComponentScan(basePackages = { "com.qmth.themis" })
 @MapperScan("com.qmth.themis.business.dao")
 //主要就是定义扫描的路径从中找出标识了需要装配的类自动装配到spring的bean容器中,做过web开发的同学一定都有用过@Controller,@Service,@Repository注解,查看其源码你会发现,他们中有一个共同的注解@Component,没错@ComponentScan注解默认就会装配标识了@Controller,@Service,@Repository,@Component注解的类到spring容器中
-@EntityScan(basePackages = {"com.qmth.themis.business.entity"})//用来扫描和发现指定包及其子包中的Entity定义
-@EnableTransactionManagement //spring开启事务支持
-@EnableAsync //开启异步任务
-@EnableCaching//开启缓存注解
+@EntityScan(basePackages = { "com.qmth.themis.business.entity" }) // 用来扫描和发现指定包及其子包中的Entity定义
+@EnableTransactionManagement // spring开启事务支持
+@EnableAsync // 开启异步任务
+@EnableCaching // 开启缓存注解
 //@EnableMongoRepositories("com.qmth.themis.backend.mongodb.repository")
 public class ThemisBackendApplication {
 
-    public static void main(String[] args) {
-        SpringApplication.run(ThemisBackendApplication.class, args);
-    }
-
-    @Resource
-    DictionaryConfig dictionaryConfig;
-
-    /**
-     * 附件上传配置
-     *
-     * @return
-     */
-    @Bean
-    public MultipartResolver multipartResolver() {
-        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
-        resolver.setDefaultEncoding(Constants.CHARSET_NAME);
-        resolver.setResolveLazily(true);//resolveLazily属性启用是为了推迟文件解析,以在在UploadAction中捕获文件大小异常
-        resolver.setMaxInMemorySize(2);//低于此值,只保留在内存里,超过此阈值,生成硬盘上的临时文件。
-        resolver.setMaxUploadSize(200 * 1024 * 1024);//最大200M
-        return resolver;
-    }
+	public static void main(String[] args) {
+		SpringApplication.run(ThemisBackendApplication.class, args);
+		init();
+	}
+
+	@Resource
+	DictionaryConfig dictionaryConfig;
+
+	/**
+	 * 附件上传配置
+	 *
+	 * @return
+	 */
+	@Bean
+	public MultipartResolver multipartResolver() {
+		CommonsMultipartResolver resolver = new CommonsMultipartResolver();
+		resolver.setDefaultEncoding(Constants.CHARSET_NAME);
+		resolver.setResolveLazily(true);// resolveLazily属性启用是为了推迟文件解析,以在在UploadAction中捕获文件大小异常
+		resolver.setMaxInMemorySize(2);// 低于此值,只保留在内存里,超过此阈值,生成硬盘上的临时文件。
+		resolver.setMaxUploadSize(200 * 1024 * 1024);// 最大200M
+		return resolver;
+	}
+
+	private static void init() {
+		SystemConfig conf=SpringContextHolder.getBean(SystemConfig.class);
+		String tempDir = conf.getProperty("sys.config.tempDataDir");
+		File dir=new File(tempDir);
+		if(!dir.exists()) {
+			dir.mkdirs();
+		}
+	}
 }

+ 1 - 0
themis-backend/src/main/resources/application.properties

@@ -127,6 +127,7 @@ sys.config.serverUpload=/Users/king/git/themis-server/
 sys.config.fileHost=localhost:6001${server.servlet.context-path}
 sys.config.serverHost=localhost:6001${server.servlet.context-path}
 spring.resources.static-locations=file:${sys.config.serverUpload},classpath:/META-INF/resources/,classpath:/resources/
+sys.config.tempDataDir=/home/project/themis/backend/files/
 
 #============================================================================
 # \u914D\u7F6Erocketmq

+ 15 - 0
themis-exam/src/main/java/com/qmth/themis/exam/ThemisExamApplication.java

@@ -1,6 +1,11 @@
 package com.qmth.themis.exam;
 
+import com.qmth.themis.business.config.SystemConfig;
+import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.common.contanst.Constants;
+
+import java.io.File;
+
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -25,6 +30,7 @@ public class ThemisExamApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ThemisExamApplication.class, args);
+        init();
     }
 
     /**
@@ -41,4 +47,13 @@ public class ThemisExamApplication {
         resolver.setMaxUploadSize(200 * 1024 * 1024);//最大200M
         return resolver;
     }
+    
+	private static void init() {
+		SystemConfig conf=SpringContextHolder.getBean(SystemConfig.class);
+		String tempDir = conf.getProperty("sys.config.tempDataDir");
+		File dir=new File(tempDir);
+		if(!dir.exists()) {
+			dir.mkdirs();
+		}
+	}
 }

+ 1 - 0
themis-exam/src/main/resources/application.properties

@@ -194,6 +194,7 @@ sys.config.serverUpload=/Users/king/git/themis-server/
 #sys.config.deviceId=1
 sys.config.fileHost=localhost:6002${server.servlet.context-path}
 sys.config.serverHost=localhost:6002${server.servlet.context-path}
+sys.config.tempDataDir=/home/project/themis/exam/files/
 spring.resources.static-locations=file:${sys.config.serverUpload},classpath:/META-INF/resources/,classpath:/resources/
 
 #api\u524D\u7F00