Request processing failed; nested exception is java.lang.IllegalArgumentException: Expected MultipartHttpServletRequest: is a MultipartResolver configured?

原因:

没有配置多部件解析器

解决方案

需要引入file-upload、common-io包

<!-- 文件上传组件 -->
<dependency>
	<groupId>commons-fileupload</groupId>
	<artifactId>commons-fileupload</artifactId>
</dependency>

<dependency>
	<groupId>org.apache.commons</groupId>
	<artifactId>commons-io</artifactId>
</dependency>

需要在springmvc.xml中配置多部件解析器,添加如下内容:

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

代码书写世界,吉他演奏生活