How can @ControllerAdvice be used to customize the response body of a global exception handler?
- By extending @ControllerAdvice from a custom class.
- By annotating the custom class with @ExceptionHandler.
- By configuring the @ControllerAdvice annotation with custom media types.
- By configuring the @ControllerAdvice annotation with @ResponseBodyAdvice classes.
@ControllerAdvice in Spring can be used to handle exceptions globally. To customize the response body, you can use @ControllerAdvice in combination with @ResponseBodyAdvice classes. These classes can customize the response format for specific exception types. The other options may be components used in the process but don't directly address customizing the response body.
Loading...
Related Quiz
- How can you customize the access-denied behavior in Spring Security for methods secured with annotations?
- You are tasked with implementing a consistent error response structure across multiple microservices developed using Spring Boot. How would you ensure that all the microservices return error responses in the same format?
- When implementing caching in Spring Boot, how can you handle cache concurrency?
- You are working on a Spring Boot application with multiple service components interacting with each other. How would you isolate and test a single service component ensuring that the interactions with other components are not affecting the test results?
- When using the @WebMvcTest annotation in Spring Boot, only the _____ are typically loaded into the application context.