title: Reuse custom hibernate validator in 2 different contexts
body: <p>I have the following custom hibernate validator in a application build with spring boot 2.1.5.</p>
  
  <pre><code>public class MyValidator implements ConstraintValidator&lt;MyValidAnnotation, DTO&gt; {
      @Autowired
      private MyBean myBean;
  
       @Override
      public boolean isValid(DTO dto, ConstraintValidatorContext constraintValidatorContext) {
          // logic
      }
  }
  </code></pre>
  
  <p>I need to use this validator in 2 cases, in isValid method I need to skip some checkings. I found a solution to set a parameter on ConstraintValidatorContext with the following code: </p>
  
  <pre><code>HibernateValidatorFactory hibernateValidatorFactory = Validation.buildDefaultValidatorFactory()
                  .unwrap( HibernateValidatorFactory.class );
  
  Validator validator = hibernateValidatorFactory.usingContext()
                  .constraintValidatorPayload(RepairEstimateDTO.class.getSimpleName())
                  .getValidator();
  
  validator.validate(dto);
  </code></pre>
  
  <p>The problem is that MyBean isn't injected, in isValid method myBean is null.</p>
  
  <p>How can I reuse this validator in 2 contexts without code duplication?</p>
  
  <p>Thanks</p>