Skip to content
Advertisement

Order between @ControllerAdvice and custom Aspect

tl;dr

How can I define the order of custom aspects and the @ControllerAdvice?

Detailed description

I want to decorate various methods (like normal REST-Calls or a @JmsListener) with MDC information on controller-level.

The idea is: I, as a developer, don’t have to think about the MDC data in my controller-methods.
I want extra MDC-information (e.g. the userId) and I can be sure, that information will be correctly removed.

my aspect

JavaScript

example controller

JavaScript

ControllerAdvice

JavaScript

Now I have a problem when a exception occurs. My aspect will always clear the MDC-context before the exception-handler jumps in. Log example:

Entered
[test=test][id=someString] Got request
[test=test][id=someString] Leaved
Uncaught exception occurred

But I want something like this:

Entered
[test=test][id=someString] Got request
[test=test][id=someString] Uncaught exception occurred
[test=test][id=someString] Leaved

I already tried to place @Order() on MdcSugar and GeneralExceptionHandler, but with no affect.

Advertisement

Answer

Sometimes the world is so easy – I only need to clear the MDC-data at the beginning.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement