Skip to content

Instantly share code, notes, and snippets.

@agrueneberg
Created November 27, 2012 23:12
Show Gist options
  • Save agrueneberg/4157870 to your computer and use it in GitHub Desktop.
Save agrueneberg/4157870 to your computer and use it in GitHub Desktop.
@ControllerAdvice in Spring MVC 3.2

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" />
</context:component-scan>
@igchuk
Copy link

igchuk commented Apr 3, 2014

I my case I was missing @EnableWebMvc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment