Manually call Spring Annotation Validation Outside of Spring MVC
问题 I have the following test that fails: @Test public void testValidation() { Validator validator = new LocalValidatorFactoryBean(); Map<String, String> map = new HashMap<String, String>(); MapBindingResult errors = new MapBindingResult(map, Foo.class.getName()); Foo foo = new Foo(); foo.setBar("ba"); validator.validate(foo, errors); assertTrue(errors.hasFieldErrors()); } Foo is as follows: import javax.validation.constraints.Size; public class Foo { @Size(min=9, max=9) private String bar; // ..