삽질방지 팁

[Spring, Tomcat] Could not parse multipart servlet request Unable to process parts as no multi-part configuration has been provided 해결

삘쏘굿 2017. 5. 4. 11:57


HTTP Status 500 - Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided

Stack trace from browser:

type Exception report

message Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided
    org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:100)
    org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.(StandardMultipartHttpServletRequest.java:78)
    org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:75)
    org.springframework.web.multipart.support.MultipartFilter.doFilterInternal(MultipartFilter.java:108)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
root cause

java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided
    org.apache.catalina.connector.Request.parseParts(Request.java:2676)
    org.apache.catalina.connector.Request.getParts(Request.java:2643)
    org.apache.catalina.connector.RequestFacade.getParts(RequestFacade.java:1083)
    org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:85)
    org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.(StandardMultipartHttpServletRequest.java:78)
    org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:75)
    org.springframework.web.multipart.support.MultipartFilter.doFilterInternal(MultipartFilter.java:108)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)

note The full stack trace of the root cause is available in the Apache Tomcat/8.0.27 logs.



위와 같은 오류가 나는데는 몇 가지 이유가 있다.


1. form의 enctype

<form name="mediaForm" method="post" enctype="multipart/form-data">



2. Controller mapping

@RequestMapping(value = "/create", method= RequestMethod.POST, 
headers = ("content-type=multipart/*"))
public ModelAndView createMedia( @RequestParam("mediaFile") MultipartFile mediaFile, @ModelAttribute MediaVO mediaVO) {



3. Tomcat8 사용하는 경우 context.xml 미작성

<?xml version="1.0" encoding="UTF-8"?>
<Context allowCasualMultipartParsing="true" path="/">
<Resources cachingAllowed="true" cacheMaxSize="100000" />
</Context>

intelliJ context.xml 생성하기 - https://brunch.co.kr/@argent/27



4. web.xml filter 미등록

<filter>
<filter-name>MultipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MultipartFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


5. bean 미등록

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