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";
}

Comment From: sbrannen

Hi @mlarchet,

Congratulations on submitting your first issue for the Spring Framework! 👍

Can you please verify that your project is being compiled with the -parameters flag?

See Parameter Name Retention in the upgrade wiki for details.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.