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 6749305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:40:28+00:00 2026-05-26T12:40:28+00:00

I’m not sure if this is possible in Spring MVC 3.0, but I’m trying

  • 0

I’m not sure if this is possible in Spring MVC 3.0, but I’m trying to create an annotated Controller that extends another Controller and whose model attributes depend on a model attribute set by the parent. For example:

@Controller
public abstract class ParentModel {

    @ModelAttribute("numbers")
    protected List<Integer> getNumbers() {
        return Arrays.asList(new Integer(1));
    }

}

@Controller
public abstract class ChildModel extends ParentModel {

    @ModelAttribute("number")
    protected Integer getNumber(@ModelAttribute("numbers") List<Integer> numbers) {
        return numbers.get(0);
    }

}

@Controller
public class RequestHandler extends ChildModel {

    @RequestMapping("/number")
    public String items(@ModelAttribute("number") Integer number) {
        return "number"; // number.jsp
    }

}

So far, I’ve been unable to get this to work – it throws the following exception:

Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]: Specified class is an interface] with root cause
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]: Specified class is an interface
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:101)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveModelAttribute(HandlerMethodInvoker.java:762) … etc …

When the dependency on the attribute set by the parent is removed from ChildModel.getNumber() (by removing the @ModelAttribute("numbers") List<Integer> numbers parameter), both model attribute methods are called. However, ParentModel.getNumbers() is always called before ChildModel.getNumber().

Please let me know if I’m missing something to get this fully working or that this is just not possible.

Thanks in advance!

EDIT:

After some more experimentation, it seems that having model attributes depend on other model attributes is probably not supported. I put both model attribute methods into the ParentModel and it works sporadically at best… The sporadic behavior is likely due to the order in which the methods are returned by reflection. When ParentModel.getNumbers() is called before ChildModel.getNumber() (the desirable order), it works properly. Having discovered this, my follow-up question is: Is there a way to specify the order in which model attribute methods are called?

  • 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-26T12:40:29+00:00Added an answer on May 26, 2026 at 12:40 pm

    I am probably using Spring model attributes incorrectly. One way to add an attribute to the model AND reuse it is to have the second (dependent) method add both of them to the model, e.g.:

    public abstract class ParentModel {
    
        // no longer annotated as model attribute
        // adds the attribute to the model if it does not exist
        protected List<Integer> getNumbers(Model model) {
            List<Integer> numbers = (List<Integer>) model.asMap().get("numbers");
            if (numbers == null) {
                numbers = Arrays.asList(new Integer(1));
                model.addAttribute("numbers", numbers);
            }
            return numbers;
        }
    
    }
    
    @Controller
    public abstract class ChildModel extends ParentModel {
    
        @ModelAttribute("number")
        protected Integer getNumber(Model model) {
            return getNumbers(model).get(0);
        }
    
    }
    

    I’m not sure if this is a good way to design Spring MVC inheriting model-populating controllers either, but for now this works.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.