HandlerExceptionResolver与注解@ControllerAdvice有什么不同啊?
来源:9-3 SpringMVC全局异常实战

youngledo
2018-05-02
我看到有的用@ControllerAdvice去处理异常,这两者有什么不同啊?
写回答
1回答
-
注解@ControllerAdvice是一个组件注解(component annotation),它允许实现类通过类路径扫描被自动检测到。当使用 MVC 命名空间或者 MVC Java 配置时自动启用。
带有@ControllerAdvice注解的类可以包含带有@ExceptionHandler、@InitBinder和@ModelAttribute注解的方法,and these methods will apply to @RequestMapping methods across all controller hierarchies as opposed to the controller hierarchy within which they are declared.
=======
总结 ControllerAdvice 有三个作用
最有用的就是配合ExceptionHandler 做异常拦截
参考:https://blog.csdn.net/w372426096/article/details/78429141
142018-05-12
相似问题