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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:34:51+00:00 2026-05-29T22:34:51+00:00

I have some beans which I create which all use a similar pattern for

  • 0

I have some beans which I create which all use a similar pattern for bean instantiation. The top objects are all very similar, but the objects they contain differ by string constructor arguments. Everything in the each top-level bean is the same except for two instances of THIS CHANGES A and one instance of THIS CHANGES B. Below is one of my beans. The others are exactly the same except for the THIS CHANGES values.

<bean id="mover1" class="CustomDataMover">
        <constructor-arg ref="session"/>
        <constructor-arg>
            <bean class="DataCache">
                <constructor-arg>
                    <bean class="AllValuesReader">
                        <constructor-arg ref="databaseConnector"/>
                        <constructor-arg value="THIS CHANGES A"/>
                        <constructor-arg value="v1"/>
                        <constructor-arg value="v2"/>
                    </bean>
                </constructor-arg>
            </bean>
        </constructor-arg>
        <constructor-arg ref="customUpdate"/>
        <constructor-arg value="THIS CHANGES B"/>
        <constructor-arg>
            <bean class="ValueGenerator">
                <constructor-arg>
                    <bean class="LatestValueRetriever">
                        <constructor-arg ref="databaseConnector"/>
                        <constructor-arg value="v3"/>
                        <constructor-arg value="v4"/>
                        <constructor-arg value="THIS CHANGES A"/>
                    </bean>
                </constructor-arg>
            </bean>
        </constructor-arg>
</bean>

How can I reduce the amount of duplication in my beans? I’m looking for some way to make some sort of template. Also, please note that I do have references to other beans.

  • 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-29T22:34:52+00:00Added an answer on May 29, 2026 at 10:34 pm

    You can use abstract bean definitions as templates to reduce duplication. For example:

    <bean id="parent" abstract="true">
        <constructor-arg value="ARG0"/>
    
        <property name="propertyA" value="A"/>
        <property name="propertyB" value="B"/>
        <property name="propertyC" ref="beanC"/>
    </bean>
    
    <bean id="child1" class="SomeClass" parent="parent">
        <property name="propertyD" value="D1"/>
    </bean>
    
    <bean id="child2" class="SomeOtherClass" parent="parent">
        <property name="propertyD" value="D2"/>
    </bean>
    

    Beans “child1” and “child2” will share values from “parent” for arg0, “propertyA”, “propertyB”, and “propertyC”, and still be able to configure their own values for “propertyD”.

    Note that “parent” has no class and therefore cannot be instantiated. Also note that “child1” and “child2” can be children of the same abstract bean definition while being completely different classes – this hierarchy has nothing to do with the class hierarchy.

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

Sidebar

Related Questions

I have a method invoking bean which calls a method to perform some sort
I have some ASP.NET web services which all share a common helper class they
I have some beans for which, in specific injections, I want to add a
I've experienced rather strange behavior of JSTL forEach tag. I have some bean called
We have some JavaEE5 stateless EJB bean that passes the injected EntityManager to its
I have some UI in VB 2005 that looks great in XP Style, but
I have some C# / asp.net code I inherited which has a textbox which
I have an EJB3 stateless session bean that uses some other ejbs to do
I have a client which connects to a Web service to get some information.
I have say list of 1000 beans which I need to share among different

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.