@RestControllerAdvice
@RestControllerAdvice is a Spring annotation that applies shared controller advice, such as exception handling, across REST controllers.
Spring Start Here, Second Edition
@RestControllerAdvice is a Spring annotation for applying shared advice, including exception handling, to REST controllers.
- How it is used
- Centralizes exception handling for REST endpoints instead of embedding exception cases in each controller action.
- How deep it goes
- Works through a payment exception handler and HTTP error response, contrasting advice with controller-level try-catch handling.
- Examples
- Uses a payment endpoint that throws NotEnoughMoneyException and returns an error message with 400 Bad Request.
- What you can do after
- Apply it with Spring annotations to move exception-response logic out of a REST controller action.
Read how Spring Start Here, Second Edition explains @RestControllerAdvice →
Testing Spring Boot Applications
@ControllerAdvice is a Spring annotation for sharing cross-controller behavior such as exception handling and data binding.
- How it is used
- Exercises shared controller behavior, especially exception handling, within focused web-layer tests.
- How deep it goes
- Demonstrates exception-to-response handling and slice inclusion, but does not detail advice implementation beyond the focused example.
- Examples
- Uses a duplicate-city exception, an HTTP 409 response, a selected city controller, and a mocked service interaction.
- What you can do after
- Diagnose web error behavior by triggering controller exceptions and asserting the resulting HTTP status and response body.
Read how Testing Spring Boot Applications explains @RestControllerAdvice →
Related concepts
- error responseproduces · An error response is a server or API response that communicates that a request or operation was unsuccessful and may provide details about the failure.
- interceptorkind of · An interceptor is a software component that intercepts operations, requests, or messages to inspect or modify them or apply behavior around their processing.
- @WebMvcTestused by · @WebMvcTest is a Spring Boot annotation that configures a focused test slice for Spring MVC components, including relevant auto-configuration.
Questions about @RestControllerAdvice
What is @RestControllerAdvice?
@RestControllerAdvice is a Spring annotation that applies shared controller advice, such as exception handling, across REST controllers.
Which Manning books explain @RestControllerAdvice?
Spring Start Here, Second Edition and Testing Spring Boot Applications.
What is @RestControllerAdvice a kind of?
@RestControllerAdvice is a kind of interceptor. An interceptor is a software component that intercepts operations, requests, or messages to inspect or modify them or apply behavior around their processing.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

