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

  • Home
  • SEARCH
  • 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 3402866
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:11:25+00:00 2026-05-18T05:11:25+00:00

I’m creating a web app using Spring 3 and would like to harness the

  • 0

I’m creating a web app using Spring 3 and would like to harness the power of the Spring Expression Language but have run into a problem. I need to set the value of a property on one of my beans to the result of a method call on another bean. I know I can do this but the issue is that the result of that method call may change after the bean is initialized and I need that property to reflect the change. For instance:

<beans>
 ...
 <bean name="guestList" class="java.util.ArrayList"></bean>

 <bean name="party" class="some.custom.class.Party">
  <property name="numberOfGuests" value="#{guestList.size()}" />
 </bean>
 ...
</beans>

From what I can tell, the numberOfGuests field is set the first time the party field is accessed. But after the party field is accessed, the number of guests may change and I need the numberOfGuests field to reflect that. Is there a way to reinitialize the numberOfGuests field within my app whenever I need the value updated?

This is just an example and accessing the guestList bean directly will not work for my specific situation.

  • 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-18T05:11:26+00:00Added an answer on May 18, 2026 at 5:11 am

    if you set your scope to prototype then each time Spring loads your bean it should recalculate the guest list size:

     <bean name="party" class="some.custom.class.Party" scope="prototype">
    

    So, party becomes prototype but guestList can stay a singleton (which is the default scope).

    There’s a catch though: if you have another bean, like partyHost (which is a singleton), and it gets injected with party (which is a prototype), partyHost will never get another instance of party, since partyHost is a singleton, and only gets dependencies injected into it once. So for this to work, all of your beans that need the updated guest list size, and all of the beans that reference them, etc. must be prototypes too.

    Either that, or you’d have to ask Spring directly via their API. If you use the API, you could call it any time you want and get a new instance of the prototype bean, and therefore the updated guest list size.

    applicationContext.getBean("myPrototype");
    

    However it’s better to avoid the Spring API if you can. Typically developers don’t want to be coupled to a DI framework.

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put

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.