java - Spring Mvc全局异常处理器@ControllerAdvice不起作用?
大家讲道理
大家讲道理 2017-04-18 10:56:55
0
1
2401

so上面一个类似的问题

自定义了一个全局的异常处理器:

@ControllerAdvice
public class ErrorController {
    @ExceptionHandler
    public ModelAndView exceptionHandler(Exception ex){
        ModelAndView mv = new ModelAndView("exception/error");
        mv.addObject("exception", ex);
        System.out.println("in testControllerAdvice");
        return mv;
    }
}

但是并没有起作用:

在相关的xml文件中已经进行了相应的设置:

    <context:component-scan base-package="org.neo.springmvclearn">
        <context:include-filter type="annotation"
            expression="org.springframework.web.bind.annotation.ControllerAdvice" />
    </context:component-scan>
    <mvc:annotation-driven/>

请问出错的原因可能有哪些?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
Peter_Zhu

The original poster’s exception handling class must be in the same directory as the controller

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!