Springboot 之修改临时文件的存储位置
报错
- 项目在线运行了一段时间后,上传文件时抛出如下异常:The temporary upload location [/tmp/tomcat.*.80/work/Tomcat/localhost/ROOT] is not valid
- 经过查找,采用了如下的解决方式【修改临时文件的位置】
location:
tempDir: /opt/location/tempDir #此处为*unix的系统相关位置
- 项目中添加配置类
@Configuration
public class MultipartConfig {
@Value("${location.tempDir:/opt/tempDir}")
private String tempDir;
@Bean
MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
File tmpDirFile = new File(tempDir);
if (!tmpDirFile.exists()) {
tmpDirFile.mkdirs();
}
factory.setLocation(tempDir);
return factory.createMultipartConfig();
}
}