标签: handlerexceptionresolver

MaxUploadSizeExceededException不会在Spring中调用异常处理方法

我正在使用Spring 3.2.0.根据这个答案,我在带注释的控制器中使用相同的方法来实现HandlerExceptionResolver接口,例如:

public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) {

    Map<String, Object> model = new HashMap<String, Object>(0);

    if (exception instanceof MaxUploadSizeExceededException) {
        model.put("msg", exception.toString());
        model.put("status", "-1");
    } else {
        model.put("msg", "Unexpected error : " + exception.toString());
        model.put("status", "-1");
    }

    return new ModelAndView("admin_side/ProductImage");
}
Run Code Online (Sandbox Code Playgroud)

和Spring配置包括,

<bean id="filterMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize">
        <value>10000</value>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

当文件大小超过时,应该调用前面的方法,它应该自动处理异常,但根本不会发生.resolveException()即使发生异常,也不会调用该方法.处理此异常的方法是什么?我错过了什么吗?

这里也指出同样的事情.我不确定为什么它在我的情况下不起作用.


我尝试了以下方法,@ControllerAdvice但它也没有用.

package exceptionhandler;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import …
Run Code Online (Sandbox Code Playgroud)

spring exception-handling file-upload spring-mvc handlerexceptionresolver

12
推荐指数
1
解决办法
7009
查看次数

如何在Spring中处理Tomcat的MaxUploadSizeExceededException?

我对此进行了一些研究,结果相互矛盾.为了处理这个错误,有人说我需要HandlerExceptionResolver在我的一个控制器中实现.

以下是一些链接:

另一方面,其他人说这种方法是徒劳的,因此Exception在请求处理流程之外发生:

我尝试了上述解决方案,但它们对我不起作用.似乎Exception发生在Spring之外,正如预期的那样.我甚至无法抓住这个HandlerExceptionResolver.

spring tomcat spring-security handlerexceptionresolver

6
推荐指数
1
解决办法
564
查看次数