How to define execution order of MethodValidationPostProcessor?

I use MethodValidationPostProcessor bean for validating method parameters of a method in Controller class. An aspect with around advice is called on this method. Any exception thrown by method on validation failure of parameters is caught by Global exception handler using ControllerAdvice. Now the problem is whenever an exception is thrown by method, it directly goes into aspect and is never caught by global exception handler. Following are code snippets –

Custom Aspect –

@Component
@Aspect
public class WebServiceAnnotationAspect implements Ordered {
// Around method

@Override
    public int getOrder() {
        return 1;
    }

}

Global custom exception –

@ControllerAdvice
public class CustomExceptionHandler {

@ExceptionHandler(CustomException.class)
public void handleIncorrectParameterException(CustomException ce) {
// some code

}

Bean defined for “MethodValidationPostProcessor” –

<bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor"/> 

When i remove the Aspect, exception is caught by global exception handler. I believe, problem is with ordering of execution of aspect.

If so, is there any way to define order of “MethodValidationPostProcessor” ?

Leave a Reply

avatar
  Subscribe  
Notify of