I want to create a standalone Spring library that handles standard api exceptions via @ControllerAdvice. My approach is to make it easy to use in different modules without any additional configuration.
There is a code of my exception handler:
@ControllerAdvice
public class ApiErrorControllerAdvice extends ResponseEntityExceptionHandler {
@ExceptionHandler(value = {ApiErrorException.class})
public ResponseEntity<ErrorResponseTo> handleApiErrorException(ApiErrorException apiError) {
return new ResponseEntity<>(
new ErrorResponseTo(apiError.getMessage()),
apiError.getHttpStatus()
);
}
}
How should I configure my application to make exception handler automatically picked up by Spring?