Its a feature in spring boot which allows pre processing such as validation, transformation and data modification on controllers and rest controllers in a centralised ways.
Uses cases of Controller advice
- Global exception handling: @ExceptionHandler within a @ControllerAdvice class to handle exceptions thrown by any controller,
- Global Data Binding and Formatting: - @InitBinder methods to configure data binding settings (e.g., custom editors or formatters) for all controllers.
- Model Attribute Population: With @ModelAttribute methods, you can add attributes to the model for all controllers, which is useful for populating common data (like user info or site-wide settings).