org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.multipart.MultipartFile]: Specified class is an interface
在報這個問題之前,首先要注意
前臺頁面
- 提交文件的input標籤是否具有name屬性
- 表單是否是以POST方式提交
- form標籤上是否有enctype="multipart/form-data"
後臺代碼
- 攔截的方法接收參數屬性是否是MultipartFile ,名稱是否和前臺name屬性一致
- 是否在配置文件中配置下面一句話
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>
id名稱必須一致
如果以上,都有做到,請在攔截方法中的MultipartFile 類型的參數前加上@RequestParam註解。
補充一點:Springmvc.xml中<mvc:annotation-driven/>是否書寫了。