Announcement Announcement Module
Collapse
No announcement yet.
@ExceptionHandler annotation not catching file upload size exceeded errors Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ExceptionHandler annotation not catching file upload size exceeded errors

    I'm trying a very straightforward (I thought) thing - catching the MaxUploadSezeExceededException and SizeLimitExceededException errors associated with file uploads.

    Here's the relevant bit in my spring-servlet.xml
    Code:
        <bean id="multipartResolver"
            class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <property name="maxUploadSize" value="100000" />
        </bean>
    And here's the @ExceptionHandler method in the controller that also handles the file upload stuff

    Code:
        @ExceptionHandler({ MaxUploadSizeExceededException.class,
                SizeLimitExceededException.class })
        public ModelAndView handleException(Exception ex) {
            System.out.println("responding to errors");
            ModelAndView model = new ModelAndView("error/generic_error.html");
            return model;
        }
    File upload is working fine. However, when I test with a file that exceeds the size limit - it throws the error, and the method for ExceptionHanler is never called.

    Any help or pointers on what else to look for / at would be greatly appreciated.

    Thanks!

  • #2
    I think the exception is thrown before the request reaches the controller; so using a custom HandlerExceptionResolver could be a solution.

    This question is probably a better candidate for StackOverflow, perhaps with the "spring-mvc" tag.

    Could you post your question there?
    The forums are moving to stackoverflow, a page explaining all this will be available there in a few days: http://spring.io/questions

    Comment

    Working...
    X