title: Spring file upload - getting Expected MultipartHttpServletRequest: is a MultipartResolver configured? error
body: <p>I'm trying to incorporate multiple file upload functionality in my Angular web application using <a href="https://github.com/nervgh/angular-file-upload">angular-file-upload</a>.  Currently, the front end functionality works, but each upload attempt throws a</p>
  
  <pre><code>java.lang.IllegalStateException,java.io.IOException]: 
      java.lang.IllegalArgumentException: Expected MultipartHttpServletRequest: 
          is a MultipartResolver configured?
  </code></pre>
  
  <p>exception.</p>
  
  <p>The Upload Controller is defined as</p>
  
  <pre><code>@Controller
  @PropertySource("classpath:application.properties")
  public class FileUploadController {
  
      @Resource
      private Environment env;
  
      @RequestMapping(value = "/fileupload", method = RequestMethod.POST)
      @ResponseBody
      public List&lt;String&gt; fileUpload(@RequestParam("file") MultipartFile[] uploadFiles) throws IllegalStateException, IOException {
          //file processing logic
      }
   }
  </code></pre>
  
  <p>In my <code>AppConfig.java</code> class, I declare the bean</p>
  
  <pre><code>@Bean
  public CommonsMultipartResolver commonsMultipartResolver(){
      CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
      commonsMultipartResolver.setDefaultEncoding("utf-8");
      commonsMultipartResolver.setMaxUploadSize(50000000);
      return commonsMultipartResolver;
  }
  </code></pre>
  
  <p>and start the web application with</p>
  
  <pre><code>@Override
  public void onStartup(ServletContext servletContext) throws ServletException {
  
      AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
      ctx.register(AppConfig.class);
      servletContext.addListener(new ContextLoaderListener(ctx));
  
      ctx.setServletContext(servletContext);
      ctx.refresh();
  
      Dynamic servlet = servletContext.addServlet(SERVLET_NAME, new DispatcherServlet(ctx));
      servlet.addMapping("/");
      servlet.setLoadOnStartup(1);
      //servlet.setMultipartConfig(ctx.getBean(MultipartConfigElement.class));
  }
  </code></pre>
  
  <p>I do not think it is due to the lack of a <code>&lt;form&gt;</code> element in my Angular view, because I can see that <code>Content-Tyle</code> is <code>multipart/form-data</code> and that the Request Payload is set appropriately.</p>
  
  <pre><code>Remote Address:192.168.33.10:80
  Request URL:http://dev.jason.com/rest/fileupload
  Request Method:POST
  Status Code:500 Internal Server Error
  Request Headers
    Accept:*/*
    Accept-Encoding:gzip,deflate
    Accept-Language:en-US,en;q=0.8
    Cache-Control:no-cache
    Connection:keep-alive
    Content-Length:415235
    Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryBHlsldPQysTVpvwZ
    Host:dev.jason.com
    Origin:http://dev.jason.com
    Pragma:no-cache
    Referer:http://dev.jason.com/
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36
  Request Payload
     ------WebKitFormBoundaryBHlsldPQysTVpvwZ
     Content-Disposition: form-data; name="file"; filename="IMG_5072.jpg"
     Content-Type: image/jpeg
  
     ------WebKitFormBoundaryBHlsldPQysTVpvwZ--
  </code></pre>
  
  <p>Note that this issue still occurs when including</p>
  
  <pre><code>@Bean
  public MultipartConfigElement multipartConfigElement(){
      MultipartConfigFactory multipartConfigFactory = new MultipartConfigFactory();
      multipartConfigFactory.setMaxFileSize("10MB");
      multipartConfigFactory.setMaxRequestSize("50MB");
      return multipartConfigFactory.createMultipartConfig();
  }
  </code></pre>
  
  <p>in <code>AppConfig.java</code> and uncommenting the command</p>
  
  <pre><code>servlet.setMultipartConfig(ctx.getBean(MultipartConfigElement.class));
  </code></pre>
  
  <p>in my servlet initializer class.</p>
  
  <p>Any help is appreciated!</p>