In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to configure the springboot temporary file storage directory". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to configure the springboot temporary file storage directory.
Springboot temporary file storage directory configuration
Scene:
The upload file function reports an error, and then troubleshoots the log.
Error log:
The temporary upload location [/ tmp/tomcat.7957874575370093230.8088/work/Tomcat/localhost/ROOT] is not valid
Reason:
On linux, when the springboot application service starts again (the java-jar command starts the service), a tomcat* file directory is generated in the / tmp directory of the operating system, and the uploaded files are first converted to temporary files and saved in this folder.
Because files in the temporary / tmp directory are not used for a long time (10 days), they will be automatically deleted by the system mechanism. So if the system does not use temporary folders for a long time, it may cause the above problem.
Solution:
1. Create a temporary folder:
Mkdir-p / tmp/tomcat.7957874575370093230.8088/work/Tomcat/localhost/ROOT
This may happen again later.
2.application.properties reconfigures a file directory and then restarts the project
# temporary folder where Tomcat logs, Dump and other files are stored. Default is the tmp folder server.tomcat.basedir=/data/apps/temp of the system
3. Configuration class configuration temporary file storage directory
@ Bean MultipartConfigElement multipartConfigElement () {MultipartConfigFactory factory = new MultipartConfigFactory (); factory.setLocation (tmepPath); return factory.createMultipartConfig ();} Springboot modifies the storage location of temporary files and reports an error
After the project has been running online for a period of time, the following exception is thrown when uploading files:
The temporary upload location [/ tmp/tomcat.*.80/work/Tomcat/localhost/ROOT] is not valid
After searching, the following solution is adopted [modify the location of the temporary file]
Add to the application.yml file
Location: tempDir:/opt/ location/tempDir # add configuration class @ Configurationpublic class MultipartConfig {@ Value ("${location.tempDir:/opt/tempDir}") private String tempDir; @ Bean MultipartConfigElement multipartConfigElement () {MultipartConfigFactory factory = new MultipartConfigFactory (); File tmpDirFile = new File (tempDir) to the system-related location project of * unix / / determine whether the folder exists if (! tmpDirFile.exists ()) {tmpDirFile.mkdirs ();} factory.setLocation (tempDir); return factory.createMultipartConfig ();}} so far, I believe you have a deeper understanding of "how to configure the springboot temporary file storage directory". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.