controller advice
A Spring class, marked @RestControllerAdvice, whose exception handlers apply across all controllers, giving one failure policy for every route.
In more detail
Centralising exception handling stops each controller inventing its own error shape. The advice maps each domain exception to a status and a problem details body, keeps details out of the response and logs them instead.
Example
@RestControllerAdvice class ApiAdvice { ... }Related terms
- @ExceptionHandler — The Spring annotation that marks a method to handle a particular exception type thrown by controllers and turn it into a response.
- Problem Details — A standard JSON shape for HTTP error responses, defined in RFC 9457, with members such as type, title, status, detail and instance.
- domain exception — An exception named for a business situation, such as OrderMissing or StorageFailure, rather than for a technical cause.
- controller (Spring) — A Spring class, usually marked @RestController, whose methods handle HTTP requests for particular paths and return response bodies.
Taught in
- Validation — Modern Java: Virtual Threads & High-Throughput Services
- Exception Handling To Problem Details — Modern Java: Virtual Threads & High-Throughput Services
- Implementing An OpenAPI Contract — Modern Java: Virtual Threads & High-Throughput Services
- Testing APIs With MockMvc — Modern Java: Virtual Threads & High-Throughput Services
- Tying It All Together — Modern Java: Virtual Threads & High-Throughput Services