Spring MultiPartResolver正在操纵其他上传方法

时间:2016-03-24 14:33:21

标签: java xml spring spring-mvc servlets

我正在尝试将两个基于Spring的项目合并为一个,但我遇到了MultiPartResolver的问题。在我的合并应用程序中,有两个类使用上传的POST方法使用不同的上传方法。 一个使用HttpServletRequest来检索上传的文件:

@RequestMapping(method = RequestMethod.POST)
public @ResponseBody void  handleResult(HttpServletRequest request,
        HttpServletResponse response)

,另一个使用MultipartFile获取文件,另一个名为notes的字段传递给表单:

@RequestMapping(method = RequestMethod.POST)
public @ResponseBody String handleFormUpload(@RequestParam("notes")
    String notes, @RequestParam("file") MultipartFile file)

然后代码引用'file'来处理上传的文件。

我遇到的问题是MultipartFile类在applicationContext.xml中需要这个:

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="250000000"/>
    </bean>

当它在applicationContext.xml文件中时,基于Servlet的原始发布方法失败。 POST请求到达此类但该文件似乎在处理它时被剥离。只要我从applicationContext.xml中注释掉它,servlet方法就会再次运行。但是,使用MultipartResolver的代码部分现在失败了!

我对Spring没有多少经验,但我正尽力做到这一点。我无法弄清楚如何防止CommonsMultipartResolver操作发往基于Servlet的类的POST文件。 有人能帮助我吗?

0 个答案:

没有答案