0

I'm tasked with removing functionality given by @ControllerAdvice(basePackages = {"com.bla.controller"}) located in an old applications. This functionality became outdated, creating some unexpected error handling issues, after another "global" functionality utilizing @ControllerAdvice got installed by a separate team. While this "global" functionality covers most needs, the old application still has a need for custom error handling, but without @ControllerAdvice. My knowledge of Spring Annotations is very limited, and I'm hoping that someone may have a good idea what can be used instead so that the old application would have awareness where to send errors for error handling. Here is an implementation sample from the file utilizing @ControllerAdvice(basePackages = {"com.bla.controller"}) notation showing both custom and basic usage in the old application:

    @ResponseStatus(HttpStatus.NOT_FOUND)
    @ExceptionHandler(ResourcePageException.class)
    public String notFound(Model model, ResourcePageException exception) {
        setAttributes(model);
        populateModel(model, exception);
        return Mapping.NO_RESULTS_VIEW;
    }
    
    @ResponseStatus(HttpStatus.NOT_FOUND)
    @ExceptionHandler(NoCustomSearchResultsRestException.class)
    public ResponseEntity<Object> locationLookupRestError(NoCustomSearchResultsRestException exception) {
        return ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getModel());
    }
user2917629
  • 883
  • 2
  • 15
  • 30

1 Answers1

0

So far I wasn't able to find a way to move all of the @ExceptionHandler methods into a single place without the use of @ControllerAdvice, but I did find this page summarizing Spring's error handling that I found useful in terms of understanding error handling by Spring: Using Spring Boot's ErrorController and Spring's ResponseEntityExceptionHandler correctly

user2917629
  • 883
  • 2
  • 15
  • 30