diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java index 9559476e9a4..4402b4f05ae 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java @@ -1575,6 +1575,7 @@ public class ServletAnnotationControllerTests { @InitBinder private void initBinder(WebDataBinder binder) { binder.initBeanPropertyAccess(); + binder.setRequiredFields("sex"); LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean(); vf.afterPropertiesSet(); binder.setValidator(vf); @@ -1582,6 +1583,15 @@ public class ServletAnnotationControllerTests { dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); } + + @Override + @RequestMapping("/myPath.do") + public String myHandle(@ModelAttribute("myCommand") @Valid TestBean tb, BindingResult errors, ModelMap model) { + if (!errors.hasFieldErrors("sex")) { + throw new IllegalStateException("requiredFields not applied"); + } + return super.myHandle(tb, errors, model); + } } @Controller