登录 后使用快捷导航
没有帐号?立即注册

IT撸码课程网

用户名   找回密码
  立即注册
发新帖

记录一次Springboot莫名其妙的错误

[复制链接]
100 226 100
发表于2018-12-05 17:13:52 | 只看楼主 | 阅读模式
登录后查看本帖详细内容!您需要登录后才可以下载 登录 | 立即注册


org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.1428942566812653608

今天突然有人反映网站不能注册了,见鬼了,本地没有任何问题,部署到服务器上就有这个问题了

    @ApiOperation(value = "新用户注册")
    @PostMapping("/user/register")
    public String registerNew(@Valid UserInfo user, BindingResult result, Model model, ServletWebRequest request) {
        if (result.hasErrors()) {
            List<ObjectError> list = result.getAllErrors();
            for (ObjectError error : list) {
                log.error(error.getDefaultMessage());
            }
            return null;
        }
        ImageCode codeInSession = (ImageCode)sessionStrategy.getAttribute(request, ValidateCodeController.SESSION_KEY);
        String code = codeInSession.getCode();
        if (!StringUtils.equalsIgnoreCase(code, user.getYzm())) {
            return "user/register.html";
        }
        userInfoService.insertUserInfo(user);
        model.addAttribute("emailAddr", MailUtil.getUserMail(user.getEmail()));
        return "user/registerActive.html";
    }

走这个方法就报错

一、异常信息

org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.1428942566812653608.8090/work/Tomcat/localhost/ROOT] is not valid
  at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest.java:122)
  at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:113)
  at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:86)
  at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:93)
  at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1128)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:960)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  at org.apache.catalina.filters.RemoteIpFilter.doFilter(RemoteIpFilter.java:876)
  at org.apache.catalina.filters.RemoteIpFilter.doFilter(RemoteIpFilter.java:913)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  at com.yooli.xcauto.heimdallrbackend.config.WebConfig$LoginPerssionmerFilter.doFilter(WebConfig.java:124)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
  at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
  at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
  at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468)
  at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: The temporary upload location [/tmp/tomcat.1428942566812653608.8090/work/Tomcat/localhost/ROOT] is not valid
  at org.apache.catalina.connector.Request.parseParts(Request.java:2859)
  at org.apache.catalina.connector.Request.parseParameters(Request.java:3232)
  at org.apache.catalina.connector.Request.getParameter(Request.java:1137)
  at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381)
  at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:84)
  ... 23 more
^C

二、分析原因

该异常为何会产生
我的应用中没有文件上传,为啥会抛org.springframework.web.multipart.MultipartException异常
2.1)首先,我们应该知道,
对于http POST请求来说,它需要使用这个临时目录来存储post数据。
2.2)其次,因为该目录是挂在到/temp目录下的临时文件,那么对于一些OS系统,像centOS将经常删除这个临时目录,所有导致该目录不存在了


三、解决方案


1.重启你的项目就可以了(我采用的这种)

你还可以尝试以下方式

2.在application.yml文件中设置multipart location ,并重启项目

spring:
  http:
    multipart:
      location: /data/upload_tmp

3.添加启动参数 -java.tmp.dir=/path/to/application/temp/,并重启

我为了安全起见,也加了第二种方案之后 再重启;


IT撸码网 - 必读申明1、本站会员可发帖,本主题所有言论和图片纯属会员个人意见,与本论坛立场无关.
2、本站所有帖子由该帖子作者发表,该帖子作者享有帖子相关权益.
3、本帖内容来网友及会员分享和其它网络媒体.
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意!
5、若因内容问题IT撸码网管理员和版主有权不事先通知发贴者而删除本文.
6、本站课程仅供本站会员学习参考,不得传播及用于其他用途,学习完后请在24小时内自行删除.
7、本站资源质量虽均经精心审查,但也难保万无一失,若发现资源有问题影响学习请一定及时点此进行问题反馈,我们会积极为您解决问题!
8、若发现链接失效了点此进行链接失效反馈,我们会第一时间修复链接.

精彩评论0

您需要登录后才可以发帖查看详细内容! 登录 | 立即注册
*
 

本版积分规则