Bläddra i källkod

fix:处理临时上传文件无效的问题

liusw 6 år sedan
förälder
incheckning
f81509cf81

+ 28 - 0
sso-server/src/main/java/com/uas/sso/MultipartConfig.java

@@ -0,0 +1,28 @@
+package com.uas.sso;
+
+import org.springframework.boot.web.servlet.MultipartConfigFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.servlet.MultipartConfigElement;
+import java.io.File;
+
+/**
+ * @author liusw
+ * @date 2019-03-06 08:59
+ */
+@Configuration
+public class MultipartConfig {
+
+    @Bean
+    MultipartConfigElement multipartConfigElement() {
+        MultipartConfigFactory factory = new MultipartConfigFactory();
+        String location = "tmp";
+        File tmpFile = new File(location);
+        if (!tmpFile.exists()) {
+            tmpFile.mkdirs();
+        }
+        factory.setLocation(location);
+        return factory.createMultipartConfig();
+    }
+}

+ 2 - 12
sso-server/src/main/java/com/uas/sso/SsoApplication.java

@@ -2,7 +2,9 @@ package com.uas.sso;
 
 import com.uas.sso.util.ContextUtils;
 import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration;
 import org.springframework.boot.context.event.ApplicationPreparedEvent;
 import org.springframework.boot.web.servlet.MultipartConfigFactory;
 import org.springframework.context.ApplicationListener;
@@ -45,16 +47,4 @@ public class SsoApplication {
         });
         application.run(args);
     }
-
-    @Bean
-    MultipartConfigElement multipartConfigElement() {
-        MultipartConfigFactory factory = new MultipartConfigFactory();
-        String location = "tmp";
-        File tmpFile = new File(location);
-        if (!tmpFile.exists()) {
-            tmpFile.mkdirs();
-        }
-        factory.setLocation(location);
-        return factory.createMultipartConfig();
-    }
 }