解决centos7上spring boot项目上传文件时候需要临时目录,项目时间长未使用被默认删除的问题

问题:centos7上spring boot项目上传文件偶尔会报错,原因是springboot上传文件会在本地有一个缓冲池,在centos7上,如果项目时间长没使用过,这个目录会被centos7删除掉,然后上传文件的时候就会报错。

/**

* 文件上传临时路径

*/

@Bean

public MultipartConfigElement multipartConfigElement(){

MultipartConfigFactory multipartConfigFactory = new MultipartConfigFactory();

String location = System.getProperty("user.dir") + "/data/tmp";

File file = new File(location);

if(!file.exists()){

file.mkdirs();

}

multipartConfigFactory.setLocation(location);

return multipartConfigFactory.createMultipartConfig();

}

 

解决办法:把上面代码写到启动类里面。

原理:把springboot上传文件时候改变临时目录,不使用centos7提供的目录。

完美解决

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章