多个ControllerAdvice优先级设定

多个ControllerAdvice,优先级由@Order决定,order的数值越小 则优先级越高。或者,实现Ordered接口,实现getOrder()方法。

import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
@ControllerAdvice 
@Order(Ordered.HIGHEST_PRECEDENCE) 
class UserProfileExceptionHandler { 
    @ExceptionHandler(UserProfileException) 
    @ResponseBody 
    ResponseEntity handleUserProfileException() { 
     .... 
    } 
} 

@ControllerAdvice 
@Order(Ordered.LOWEST_PRECEDENCE) 
class DefaultExceptionHandler { 

    @ExceptionHandler(RuntimeException) 
    @ResponseBody 
    ResponseEntity handleRuntimeException() { 
     .... 
    } 
} 

你可能感兴趣的:(spring)