title: MultipartResolver and AbstractAnnotationConfigDispatcherServletInitializer
body: <p>I'm having trouble using <code>CommonsMultipartResolver</code> bean in conjunction with an initializer that extends <code>AbstractAnnotationConfigDispatcherServletInitializer</code>.</p>
  
  <p>I have successfully used CommonsMultipartResolver in a previous project, but the initializer implements <code>WebApplicationInitializer</code>.</p>
  
  <p>Intuitively, I did this in the initializer extending <code>AbstractAnnotationConfigDispatcherServletInitializer</code>.</p>
  
  <pre><code>@Override
    protected Class&lt;?&gt;[] getRootConfigClasses() {
      return new Class&lt;?&gt;[]{
          MultipartUploadConfig.class
      };
    }
  
    @Override
    protected Class&lt;?&gt;[] getServletConfigClasses() {
      return new Class&lt;?&gt;[]{
          WebMvcConfig.class
  
      };
    }
  </code></pre>
  
  <p>I thought it would have the same effect as with this code in <code>WebApplicationInitializer</code> (This is the working config).</p>
  
  <pre><code>@Override
      public void onStartup(ServletContext servletContext) throws ServletException {
          AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
          dispatcherServlet.register(WebMvcConfig.class);
  
          ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet));
          dispatcher.setLoadOnStartup(1);
          dispatcher.addMapping("/");
  
          AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
          rootContext.register(MultipartUploadConfig.class);
  
          servletContext.addListener(new ContextLoaderListener(rootContext));
      }
  </code></pre>
  
  <p>Using <code>AbstractAnnotationConfigDispatcherServletInitializer</code>, I get the following error:</p>
  
  <pre><code>Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided
  </code></pre>
  
  <p>So, anyone knows how to make multipartResolver bean work with <code>AbstractAnnotationConfigDispatcherServletInitializer</code>?</p>
  
  <p>Other relevant information:</p>
  
  <p>WebMvcConfig.java</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = ...)
  public class WebMvcConfig extends WebMvcConfigurerAdapter {
    ...
  
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
      configurer.enable();
    }
  
  }
  </code></pre>
  
  <p>MultipartUploadConfig.java</p>
  
  <pre><code>@Configuration
  public class MultipartUploadConfig {
  
    @Bean
    public CommonsMultipartResolver multipartResolver() {
      CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
      multipartResolver.setMaxUploadSize(8192);
      multipartResolver.setDefaultEncoding("utf-8");
      return multipartResolver;
    }
  }
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>[http-nio-8080-exec-4] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [] threw 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
      at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:100)
      at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.&lt;init&gt;(StandardMultipartHttpServletRequest.java:78)
      at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:76)
      at org.springframework.web.multipart.support.MultipartFilter.doFilterInternal(MultipartFilter.java:108)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
      at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided
      at org.apache.catalina.connector.Request.parseParts(Request.java:2669)
      at org.apache.catalina.connector.Request.getParts(Request.java:2636)
      at org.apache.catalina.connector.RequestFacade.getParts(RequestFacade.java:1083)
      at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:85)
      ... 23 more
  </code></pre>