Skip to content

Implicit @ModelAttribute no longer works #34907

Open
@mlarchet

Description

@mlarchet

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: waiting-for-feedbackWe need additional information before we can continuestatus: waiting-for-triageAn issue we've not yet triaged or decided on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions