spring mvc 上传时
org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
解决方法
添加配置:
- < bean id = "multipartResolver"
- class = "org.springframework.web.multipart.commons.CommonsMultipartResolver" >
- <!-- set the max upload size100MB -->
- < property name = "maxUploadSize" >
- < value > 104857600 </ value >
- </ property >
- < property name = "maxInMemorySize" >
- < value > 4096 </ value >
- </ property >
- </ bean >
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- set the max upload size100MB --> <property name="maxUploadSize"> <value>104857600</value> </property> <property name="maxInMemorySize"> <value>4096</value> </property> </bean>
问题解决.
简单分析:
当Web请求到达DispatcherServlet并等待处理的时候,DispatcherServlet首先会检查能否从自己的WebApplicationContext中找到一个名称为multipartResolver(由DispatcherServet的MULTIPART_RESOLVER_BEAN_NAME决定)实例.如果能获得这个实例,DispatcherServlet将通过MultipartResolver的isMultipart(request)方法检查当前Web请求是否为multipart类型.如果是,DispatcherServlet将调用MultipartResolver的resolveMultipart(request)方法,返回MultipartHttpServletRequest,否则返回HttpServletRequest.
SpringMVC为MultipartResolver提供了两个实现类,org.springframework.web.multipart.commons.CommonsMultipartResolver使用apache的commons fileupload实现,org.springframework.web.multipart.cos.CosMultipartResolver使用Oreilly Cos实现,因此必须选择这两个实现类中的一个,然后添加到DispatcherServlet的WebApplicationContext,例如如果使用commons upload则添加上面的代码到XML,这样CommonsMultipartResolver/CosMultipartResolver将负责分析当前multipart的请求.
org.apache.catalina.connector.RequestFacade cannot be cast to org.springframewor