java.lang.IllegalArgumentException: Expected MultipartHttpServletRequest: is a MultipartResolver con

異常信息:  2014-8-4 18:29:42 org.apache.catalina.core.StandardWrapperValve invokejava

嚴重: Servlet.service() for servlet springServlet threw exception java.lang.IllegalArgumentException: Expected MultipartHttpServletRequest: is a MultipartResolver configured?   web

at org.springframework.util.Assert.notNull(Assert.java:112)   spring

at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.resolveName(RequestParamMethodArgumentResolver.java:151)   apache

at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:86)    ...   tomcat

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)   mvc

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)   app

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)   .net

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)   ip

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)   servlet

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)   

at java.lang.Thread.run(Thread.java:662)

 

解決方法:  

spring mvc中上傳附件,須要作兩步操做

1.引入包commons-fileupload-1.3.jar,版本號能夠根據項目狀況調整;  

2.在spring mvc配置文件中增長配置,文件大小限制可根據項目狀況調整:

<!-- 上傳文件攔截,設置最大上傳文件大小   10M=10*1024*1024(B)=10485760 bytes --> 

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

      <property name="maxUploadSize" value="10485760" /> 

</bean>

相關文章
相關標籤/搜索