admin管理员组

文章数量:1794759

spring MVC报错 Expected MultipartHttpServletRequest: is a MultipartResolver configured?

spring MVC报错 Expected MultipartHttpServletRequest: is a MultipartResolver configured?

在使用spring MVC进行图片上传的时候,报错

严重: Servlet.service() for servlet [taotao-manager] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: Expected MultipartHttpServletRequest: is a MultipartResolver configured?] with root cause java.lang.IllegalArgumentException: Expected MultipartHttpServletRequest: is a MultipartResolver configured? at org.springframework.util.Assert.notNull(Assert.java:112) .......

这是由于在spring MVC进行文件上传的时候,需要在springmvc.xml文件中配置多部件解析器。注:需要引入文件上传的jar包,file-upload和common-io

配置如下:

<!-- 定义文件上传解析器 --> <bean id="multipartResolver" class="org.springframework.web.multipartmons.CommonsMultipartResolver"> <!-- 设定默认编码 --> <property name="defaultEncoding" value="UTF-8"></property> <!-- 设定文件上传的最大值5MB,5*1024*1024 --> <property name="maxUploadSize" value="5242880"></property> </bean>

重启tomcat,问题解决。

本文标签: 报错MVCspringexpectedconfigured