Open
Description
After upgrading from spring-boot 2.7 to spring-boot 3.4, implicit @ModelAttribute
annotation doesn't work anymore.
@Autowired
MyBeanValidator myBeanValidator;
@ModelAttribute("myBean")
public MyBean getMyBean() {
return new MyBean();
}
@PostMapping("/addMyBean")
public String doAddMyBean(@ModelAttribute MyBean myBean, BindingResult result) {
myBeanValidator.validate(myBean, result);
if(result.hasErrors()) {
return "add-my-bean";
}
...
}
Doing this doesn't work anymore: in case of validation error, form is displayed empty and error messages are not displayed (#fields.hasErrors
does not trigger) as if the backing bean was cleared.
Using explicit @ModelAttribute
name fixes the problem :
@PostMapping("/addMyBean")
public String doAddMyBean(@ModelAttribute("myBean") MyBean myBean, BindingResult result) {
return "add-my-bean";
}