Spring MVC 3.2 introduces the @ControllerAdvice
component annotation that allows you define single @ExceptionHandler
methods for all your controllers.
If you find yourself that the exception handlers are not working the way they are supposed to and you happen to have a clearly separated root and web scope, make sure that that you are including the @ControllerAdvice
component in the web scope rather than the root scope, i.e. include org.springframework.web.bind.annotation.ControllerAdvice
in context:component-scan
:
<context:component-scan base-package="[path]" use-default-filters="false">
<context:include-filter expression="org.springframework.stereotype.Controller" type="annotation" />
<context:include-filter expression="org.springframework.web.bind.annotation.ControllerAdvice" type="annotation" />