无法解析多部分servlet请求;嵌套异常是org.apache.commons.fileupload.FileUploadException:打开的文件太多

时间:2017-03-07 18:51:16

标签: java spring

我在高度要求的控制器上的方法中遇到此错误。这是一个接收JSON的简单POST。

这种方法是这样的:

@PostMapping("/")
@ResponseBody
public A query(B obj){
...
}

New Relic展示了以下堆栈跟踪:

Error message
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: Too many open files

Sample stack trace
…ultipart.commons.CommonsMultipartResolver.parseRequest (CommonsMultipartResolver.java:168)

…part.commons.CommonsMultipartResolver.resolveMultipart (CommonsMultipartResolver.java:142)

…framework.web.servlet.DispatcherServlet.checkMultipart (DispatcherServlet.java:1099)

…ringframework.web.servlet.DispatcherServlet.doDispatch (DispatcherServlet.java:932)
...
caused by org.apache.commons.fileupload.FileUploadException: Too many open files
….apache.commons.fileupload.FileUploadBase.parseRequest (FileUploadBase.java:362)
…mons.fileupload.servlet.ServletFileUpload.parseRequest (ServletFileUpload.java:115)
…ultipart.commons.CommonsMultipartResolver.parseRequest (CommonsMultipartResolver.java:158)
…part.commons.CommonsMultipartResolver.resolveMultipart (CommonsMultipartResolver.java:142)
…framework.web.servlet.DispatcherServlet.checkMultipart (DispatcherServlet.java:1099)
…ringframework.web.servlet.DispatcherServlet.doDispatch (DispatcherServlet.java:932)
…pringframework.web.servlet.DispatcherServlet.doService (DispatcherServlet.java:897)
…gframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doPost (FrameworkServlet.java:872)
                 javax.servlet.http.HttpServlet.service (HttpServlet.java:707)
…g.springframework.web.servlet.FrameworkServlet.service (FrameworkServlet.java:846)
                 javax.servlet.http.HttpServlet.service (HttpServlet.java:790)
…undertow.servlet.handlers.ServletHandler.handleRequest (ServletHandler.java:85)

有没有人经历过这样的事情?

1 个答案:

答案 0 :(得分:0)

删除标题可以正常工作。当我从弹簧控制器向角度发送请求时,我遇到了同样的问题。 这是我使用angular抛出相同错误的代码。

let formData:FormData = new FormData();
    formData.append('file', file, file.name);
    let headers = new Headers();
    headers.append('Content-Type', 'multipart/form-data')
    headers.append('Accept', 'application/json');
let options = new RequestOptions({ headers: headers });
    this.http.post(URL_API_REST + 'upload', formData, options)  

在下面注释掉这一行解决了这个问题,因为我没有处理弹簧控制器中的multipart / form-data:

headers.append('Content-Type', 'multipart/form-data')