MethodParameterValidatorConstraintResolver extends ValidatorConstraintResolver implements MethodParameterConstraintResolver { @Override public List<Constraint> resolveForParameter(MethodParameter param) { if (CONSTRAINT_CLASS == null) { return Collections.emptyList(); } List<Constraint> constraints = new ArrayList<>(); for (Annotation annot : param.getParameterAnnotations()) { Class<? extends Annotation> type = annot.annotationType(); if (type.getAnnotation(CONSTRAINT_CLASS) != null) { Constraint constraint = createConstraint(annot, type); constraints.add(constraint); } } return constraints; }  @Override List<Constraint> resolveForParameter(MethodParameter param);  }
@Test public void resolveConstraints() throws NoSuchMethodException { MethodParameterConstraintResolver resolver = new MethodParameterValidatorConstraintResolver(); Method method = ConstraintTest.class.getMethod("method", Long.class, String.class); List<Constraint> constraints = resolver.resolveForParameter(new MethodParameter(method, 0)); assertThat(constraints.size(), is(2)); Constraint constraint = constraints.get(0); assertThat(constraint.getName(), is(NotNull.class.getName())); Map<String, Object> config = constraint.getConfiguration(); assertThat(config.size(), is(3)); constraint = constraints.get(1); assertThat(constraint.getName(), is(Min.class.getName())); config = constraint.getConfiguration(); assertThat(config.size(), is(4)); assertThat(config.get("value"), is((Object) 1L)); assertThat(config.get("groups"), is((Object) new Object[]{Create.class})); constraints = resolver.resolveForParameter(new MethodParameter(method, 1)); assertThat(constraints.size(), is(2)); constraint = constraints.get(0); assertThat(constraint.getName(), is(NotBlank.class.getName())); config = constraint.getConfiguration(); assertThat(config.size(), is(3)); constraint = constraints.get(1); assertThat(constraint.getName(), is(OneOf.class.getName())); config = constraint.getConfiguration(); assertThat(config.size(), is(4)); assertThat(config.get("value"), is((Object) new Object[]{"one", "two", "three"})); }