Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6042623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:48:40+00:00 2026-05-23T06:48:40+00:00

We are working on a Spring 3.0.5 Web MVC-based application. In our code we

  • 0

We are working on a Spring 3.0.5 Web MVC-based application. In our code we quite often do something like this:

@ModelAttribute(ModelKeys.SOME_BEAN)
public SomeBean newSomeBean() {
  return new SomeBean();
}

I think this is not necessary. But if it really wasn’t, then I wonder how has this managed to slip through so many code reviews? In my understanding, if a controller method wanted a NEW SomeBean, then annotating a parameter in that method with @ModelAttribute should be enough? Spring would then use the default constructor to new up the required bean for invoking the controller method, e.g.:

@RequestMapping(method = RequestMethod.POST)
public String doIt(
  @ModelAttribute(ModelKeys.SOME_BEAN) final SomeBean bean,
  final BindingResult bindingResult)
{
  ...
}

here, Spring would new up an instance of SomeBean and try to data-bind into it from the POSTed data, right? There’s no need for the method as shown in the first code snippet? Please can you confirm this or provide me with your thoughts on this? Would I be introducing a risk if I just went ahead and removed all these methods that do nothing other than new up an empty bean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:48:40+00:00Added an answer on May 23, 2026 at 6:48 am

    @ModelAttribute annotation on a method does not bind the bean attributes with HTTP request parameters. This is the key difference from the same annotation on a method parameter. Such approach is useful to populate some data that does not depend on request parameters in the model, for instance, values of a comboboxes taken from dictionaries. This is especially helpful, if you have several handler methods in a controller, e.g. to view/change/delete the same type of object and you need the same set of model attributes in all of them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Java web application (Adobe Flex front-end, JPA/Hibernate/BlazeDS/Spring MVC backend) and
I'm writing web application that uses Spring MVC to bind Spring beans with REST-like
I'm working on a reporting web application using JasperReport and Spring MVC 3 to
I'm working with integration Spring Web Flow into Spring MVC web application. I mapped
I'm working on a Spring MVC 3 web application, I have some JSPs that
I'm working on a reporting web application using JasperReports and Spring MVC. Now, i
i am working with some other people on a Spring MVC web application. If
When working with web-designers in a Spring-MVC and JSP environment, are there any tools
I've set up a CRUD web application with Spring Roo and Spring MVC. My
I have a working Spring MVC application(doing everything I wanted when deployed to jboss)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.