Recently, I want to use @Exceptionhandler to handle different exceptions, but I found that HttpMediaTypeException and UnsupportedMediaTypeException were not handled by my UnsupportedMediaTypeExceptionHandler,
but caught by my UnexpectedExceptionHandlerHandler
Then I found the reason is ExceptionHandlerExceptionResolver.getExceptionHandlerMethod(@Nullable HandlerMethod handlerMethod, Exception exception) when processing,
it executed in sequence according to the key order of the Map
The UnexpectedExceptionHandlerHandler was catch any exception, and it was in front of the UnsupportedMediaTypeExceptionHandler. That's why it caused such a tragedy, so I want to ask how to make my UnexpectedExceptionHandlerHandler execute finally.
At present, my method is to rename my UnexpectedExceptionHandlerHandler to ZzUnexpectedExceptionHandlerHandler to ensure its final execution😀😀😀
Comment From: RovingSea
If it can't achieve through the existing code, can developers judge the locking type first and then execute the added @ExceptionHandler method?
Comment From: kse-music
you can set order annotation or implements Ordered interface
@Order(0)
public class UnsupportedMediaTypeExceptionHandler {}
Comment From: RovingSea
you can set order annotation or implements Ordered interface
@Order(0) public class UnsupportedMediaTypeExceptionHandler {}
I tried, but it didn't work, and set @Order(Integer.MIN_VALUE)
Comment From: RovingSea
Today, I chose a better method, which is to add @Order(Ordered.HIGHEST_PRECEDENCE) to other ExceptionHandlers. 😅😅