1. 程式人生 > >Spring boot(16) spring boot 線上故障 上傳檔案出錯:org.springframework.web.multipart.MultipartException: Could

Spring boot(16) spring boot 線上故障 上傳檔案出錯:org.springframework.web.multipart.MultipartException: Could

上線後,過了一段時間上傳檔案的時候
出現錯誤
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.2737591724424319502.8062/work/Tomcat/localhost/ROOT] is not valid
臨時檔案地址無效


解決方法:
①啟動時增加引數-Djava.io.tmpdir=/data/web/williamy/temp
 /usr/local/services/jdk1.8.0_91/bin/java -jar hq_demo-52.jar -Djava.io.tmpdir=/data/web/williamy/temp --spring.profiles.active=demo
②提供檔案上傳臨時路徑
@Bean
 MultipartConfigElement multipartConfigElement() {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    factory.setLocation("/app/pttms/tmp");
    return factory.createMultipartConfig();
}

③修改application.properties

server.tomcat.basedir=${user.home}/deployer/tomcat