Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

Spring Mvc全局异常处理器@ControllerAdvice不起作用?

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/>

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

楼主的这个异常处理类要和controller在同一级目录


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...