org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nes

简介: org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nes

Spring Boot项目跑一段时间就出现了异常

1.异常

[/tmp/tomcat.2963812887341900572.9000/work/Tomcat/localhost/ROOT] is not valid, e={}
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.2963812887341900572.9000/work/Tomcat/localhost/ROOT] is not valid
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest.
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.(StandardMultipartHttpServletRequest.
at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.
at
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.
at
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.
at
at
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.
at
Caused by: java.io.IOException: The temporary upload location [/tmp/tomcat.2963812887341900572.9000/work/Tomcat/localhost/ROOT] is not valid
at org.apache.catalina.connector.Request.parseParts(Request.
at org.apache.catalina.connector.Request.parseParameters(Request.
at org.apache.catalina.connector.Request.getParameterNames(Request.
at org.apache.catalina.connector.Request.getParameterMap(Request.
at org.apache.catalina.connector.RequestFacade.getParameterMap(RequestFacade.
at org.springframework.web.servlet.DispatcherServlet.lambda$logRequest$2(DispatcherServlet.
at org.springframework.core.log.LogFormatUtils.traceDebug(LogFormatUtils.
at org.springframework.web.servlet.DispatcherServlet.logRequest(DispatcherServlet.
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.
... 34 common frames omitted
2020-02-17 10:45:29 -返回错误:code=999, msg=服务器出错了请稍后尝试.....

2.解决

1.SpringBoot项目运行一段时间上传文件出现这样的错误。

PS:错误信息很明显说是没有这个目录,linux过段时间就会自动清理一下tmp的一个临时目录,当然这个目录被清理的也就找不到了也就是报异常了

2.解决办法有3种:

1)mkdir -p /tmp/tomcat.2963812887341900572.9000/work/Tomcat/localhost/ROOT

2)重启项目

3)自定义Tomcat的工作目录

在application.yml中增加以下配置,basedir后面跟一个“.”表示项目的启动目录。

server:
  tomcat:
    basedir: .
相关文章
|
1月前
|
Java 应用服务中间件 Spring
【终极解决方案】Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
【终极解决方案】Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
26 0
|
1月前
|
Java Spring
【亲测有效完结bug】org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exce
【亲测有效完结bug】org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exce
160 0
|
2月前
|
前端开发 Java
org.springframework.web.multipart.MultipartException: Current request is not a multipart request
org.springframework.web.multipart.MultipartException: Current request is not a multipart request
65 0
|
3月前
|
存储 缓存 前端开发
Servlet与JSP在Java Web应用中的性能调优策略
Servlet与JSP在Java Web应用中的性能调优策略
33 1
|
3月前
|
C# 数据可视化 开发者
WPF开发者福音:深度解析OxyPlot与LiveCharts图表库,轻松实现数据可视化不再是难题!
【8月更文挑战第31天】在WPF应用中,数据可视化对提升用户体验至关重要。本文介绍并演示了两种流行图表库OxyPlot和LiveCharts的集成与使用方法。OxyPlot是一款适用于.NET应用的开源图表库,提供多种图表类型,易于集成。LiveCharts则以其丰富的图表类型和动画效果,特别适合实时数据展示。通过具体代码示例,本文展示了如何利用这两种图表库创建折线图和柱状图,并详细说明了安装和配置步骤。希望本文能帮助开发者在WPF应用中轻松实现高效、美观的数据可视化。
197 0
|
3月前
|
存储 Java 关系型数据库
基于Servlet和JSP的Java Web应用开发指南
基于Servlet和JSP的Java Web应用开发指南
49 0
|
3月前
|
监控 前端开发 Java
揭秘Web开发神器:Servlet、过滤器、拦截器、监听器如何联手打造无敌博客系统,让你的用户欲罢不能!
【8月更文挑战第24天】在Java Web开发中,Servlet、过滤器(Filter)、拦截器(Interceptor,特指Spring MVC中的)及监听器(Listener)协同工作,实现复杂应用逻辑。以博客系统为例,Servlet处理文章详情请求,过滤器(如LoginFilter)检查登录状态并重定向,Spring MVC拦截器(如LoggingInterceptor)提供细粒度控制(如日志记录),监听器(如SessionListener)监控会话生命周期事件。这些组件共同构建出高效、有序的Web应用程序。
39 0
|
3月前
|
开发框架 中间件 .NET
分享 ASP.NET Core Web Api 中间件获取 Request Body 两个方法
分享 ASP.NET Core Web Api 中间件获取 Request Body 两个方法
123 0
|
5月前
|
存储 Java 关系型数据库
基于Servlet和JSP的Java Web应用开发指南
【6月更文挑战第23天】构建Java Web应用,Servlet与JSP携手打造在线图书管理系统,涵盖需求分析、设计、编码到测试。通过实例展示了Servlet如何处理用户登录(如`LoginServlet`),JSP负责页面展示(如`login.jsp`和`bookList.jsp`)。应用基于MySQL数据库,包含用户和图书表。登录失败显示错误信息,成功后展示图书列表。部署到Tomcat服务器测试功能。此基础教程为深入Java Web开发奠定了基础。
107 10
|
5月前
|
缓存 负载均衡 安全
Servlet与JSP在Java Web应用中的性能调优策略
【6月更文挑战第23天】在Java Web中,Servlet和JSP调优至关重要,以应对高并发和复杂业务带来的性能挑战。优化包括Servlet复用、线程安全、数据库连接池,以及JSP的编译优化、使用JSTL、页面缓存和静态内容分离。全局优化涉及负载均衡、异步处理和缓存策略。通过这些实践,开发者能提升应用响应速度和吞吐量,确保高负载下的稳定运行。
78 7