title: Convert JSR303 JavaBean Validation exceptions to custom exceptions
body: <p>I have implemented the JSR303 JavaBean Validation in the Service layer of my web app (according to <a href="http://musingsofaprogrammingaddict.blogspot.com/2011/01/method-validation-with-hibernate.html" rel="nofollow">this article</a>). Now I want to convert all validation exceptions (e.g. javax.validation.ConstraintViolationException) to my custom exception.</p>
  
  <p>I created an Aspect that is invoked whenever an exception is thrown in the Service layer:</p>
  
  <pre><code>@Aspect
  public class ExceptionConversionAspect {
  
      @AfterThrowing(pointcut="execution(* com.myexample.service.*.*(..))", throwing="e")
      public void convertServiceException(Exception e) {
  
          if (e instanceof ConstraintViolationException) {
               // this is my custom exception
              throw new InvalidServiceInputException("The service inputs failed validation", e);
          }
      }
  }
  </code></pre>
  
  <p>But my exception conversion aspect is not triggered when my service fails validation with ConstraintViolationException. I suspect this is because the validation exception is itself triggered by an Aspect:</p>
  
  <pre><code>@Aspect
  public class ValidateAspect {
  
      @Autowired
      private Validator validator;
  
      // Match any public methods in a class annotated with @AutoValidating
      @Around("execution(public * *(..)) &amp;&amp; @within(com.myexample.validator.annotation.Validate)")
      public Object validateMethodInvocation(ProceedingJoinPoint pjp) throws Throwable {
  
      // some code here
      ....
  }
  </code></pre>
  
  <p>How do I chain my aspects in the correct order? ValidateAspect first, followed by ExceptionConversionAspect?</p>