在運行springboot時 ,長時間運行后報錯 the temporary uplaod location *** is not valid 查過資料后發現是centos對‘/temp’下文件自動清理的原因。 在springboot項目啟動后 系統會在‘/temp’目錄下創建幾個目錄 用於上傳文件。因此清理過‘/temp’下文件后無法上傳
解決方法: 1 重啟服務;
2 改變臨時文件的存儲路徑
@Configuration public class MultipartConfig{ /** *文件臨時上傳路徑 */ @Bean MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); String location = System.getProperty("user.dir") +"/data/tmp"; File tmpFile =new File (location); if(!tmpFile.exists()){ tmpFile.mkdirs(); } Factory.setLocation(location); return factory.createMultipartConfig(); } }