Javascript org.springframework.web.multipart.support.MissingServletRequestPartException:必需的请求部分';文件';不在场

Javascript org.springframework.web.multipart.support.MissingServletRequestPartException:必需的请求部分';文件';不在场,javascript,ajax,spring,Javascript,Ajax,Spring,当我试图发送一个很棒的文件时,我遇到了问题。当文件很小时,没有问题 控制器 @SuppressWarnings({ "unchecked", "rawtypes" }) @RequestMapping(value = "newFile", method = RequestMethod.POST) @ResponseBody public JSONObject newFile(final HttpSession s

当我试图发送一个很棒的文件时,我遇到了问题。当文件很小时,没有问题

控制器

@SuppressWarnings({ "unchecked", "rawtypes" })
    @RequestMapping(value = "newFile", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject newFile(final HttpSession session, final HttpServletResponse response,
            @RequestPart("document") final DocumentAjusteDTO dto, @RequestPart("file") final MultipartFile file)
            throws IOException {
js

当文件小于5mb时,ok。 文件>5mb ko

这是tomcat日志

HandlerMethod details:
Controller [com.isb.hpa.ajustes.web.controllers.AjustesController]
Method [public org.jose4j.json.internal.json_simple.JSONObject com.isb.hpa.ajustes.web.controllers.AjustesController.newFile(javax.servlet.http.HttpSession,javax.servlet.http.HttpServletResponse,com.isb.hpa.logic.rest.beans.DocumentAjusteDTO,org.springframework.web.multipart.MultipartFile) throws java.io.IOException]

org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'document' is not present
        at ....

您的异常表示您的请求中没有“文档”。如果您的请求仅包含多部分文件,则可以向参数中添加
required=false

@RequestPart("document",  required = false) final DocumentAjusteDTO dto
将以下属性添加到应用程序以避免文件大小错误:

spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=12MB
如果文件较大,请将10和12更改为较大的数字

另外,如前所述,将以下标题添加到Ajax请求中

内容类型:未定义。这将导致浏览器将内容类型设置为“多部分/表单数据”,并正确填充边界。手动将内容类型设置为多部分/表单数据将无法填写请求的边界参数


我需要文件,我只能用application.properties证明,当我在本地工作时,这个问题不存在。当我尝试将其上载到服务器时,出现了问题啊,可能是因为您的端点不匹配,您的服务器等待来自@RequestMapping(value=“newFile”,…)的请求。您向目标发送请求:“new_file”,将映射值更改为new_file,如果它不能解决您的问题,请提供stacktracei,我有一个配置ajax.js,在那里我在new_文件中转换de newFile。
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=12MB
headers: {
         "Content-Type": undefined
  },