title: Changing file size limit (maxUploadSize) depending on the controller
body: <p>I have a Spring MVC web with two different pages that have different forms to upload different files. One of them should have a limitation of 2MB, while the other should have a 50MB limitation.</p>
  
  <p>Right now, I have this limitation in my app-config.xml:</p>
  
  <pre><code>&lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
      &lt;!-- one of the properties available; the maximum file size in bytes (2097152 B = 2 MB) --&gt;
      &lt;property name="maxUploadSize" value="2097152 "/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>And I could resolve the maxUploadSize exception in my main controller like that:</p>
  
  <pre><code>@Override
  public @ResponseBody
  ModelAndView resolveException(HttpServletRequest arg0,
          HttpServletResponse arg1, Object arg2, Exception exception) {
      ModelAndView modelview = new ModelAndView();
          String errorMessage = "";
          if (exception instanceof MaxUploadSizeExceededException) {
              errorMessage =  String.format("El tamaño del fichero debe ser menor de  %s", UnitConverter.convertBytesToStringRepresentation(((MaxUploadSizeExceededException) exception)
                      .getMaxUploadSize()));
  
          } else {
              errorMessage = "Unexpected error: " + exception.getMessage();
          }
          saveError(arg0, errorMessage);
          modelview = new ModelAndView();
          modelview.setViewName("redirect:" + getRedirectUrl());
      }
      return modelview;
  }
  </code></pre>
  
  <p>But this, obviously, only controlls the 2MB limit. How could I make the limitation for the 20MB one?
  I've tried this solution: <a href="https://stackoverflow.com/a/11792952/1863783">https://stackoverflow.com/a/11792952/1863783</a>, which updates the limitation in runtime. However, this updates it for every session and every controller. So, if one user is uploading a file for the first form, another using uploading in the second form should have the limitation of the first one...</p>
  
  <p>Any help? thanks</p>