转自:https://blog.csdn.net/iteye_17476/article/details/82651580

java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest

 

一、详细的错误信息(解决方法在下面):

 

  1.  
    java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
  2.  
    at com.lqy.spring.iwx.controller.BaseController.getFileEntityAfterUpoad(BaseController.java:429)
  3.  
    at com.lqy.spring.iwx.controller.backend.weixin.WxMaterialController.uploadMaterial(WxMaterialController.java:192)
  4.  
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  5.  
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  6.  
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  7.  
    at java.lang.reflect.Method.invoke(Unknown Source)
  8.  
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
  9.  
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
  10.  
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
  11.  
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:775)
  12.  
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
  13.  
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
  14.  
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
  15.  
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
  16.  
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:965)
  17.  
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:867)
  18.  
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
  19.  
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:841)
  20.  
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  21.  
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
  22.  
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  23.  
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
  24.  
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  25.  
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  26.  
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  27.  
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
  28.  
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
  29.  
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
  30.  
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
  31.  
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  32.  
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
  33.  
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
  34.  
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
  35.  
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
  36.  
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
  37.  
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
  38.  
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
  39.  
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  40.  
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  41.  
    at java.lang.Thread.run(Unknown Source)

 

 

二、解决方法:在SpringMvc.xml文件中增加Spring文件上传的解析器,如下

 

<!-- 上传文件拦截,设置最大上传文件大小 10M=10*1024*1024(B)=10485760 bytes -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="maxUploadSize" value="10485760" />
		<!-- resolveLazily属性启用是为了推迟文件解析,以便在Action 中捕获文件大小异常 -->
		<property name="resolveLazily" value="true" />
		<property name="defaultEncoding" value="UTF-8" />
	</bean>
posted on 2018-12-26 02:01  Sharpest  阅读(1803)  评论(0编辑  收藏  举报