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

The Archive Base Latest Questions

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

I’ve got a bean (id=myBean) defined in e.g. core.xml. myBean is NOT abstract, and

  • 0

I’ve got a bean (id=”myBean”) defined in e.g. core.xml. myBean is NOT abstract, and its definition in this file CANNOT be modified.

However I need to set a new property (myProperty) somehow, in a separate XML file (overrides.xml) that is loaded after core.xml is loaded at a particular client site.

If I redefine the bean a second time, and this time give myProperty a value, Spring (2.5) rejects it as a duplicate bean definition (fair enough).

I was wondering how to set this property in overrides.xml without breaking/changing the original bean definition.

Guessing AOP and possibly an AutoProxy is somehow the way to do achieve this but so far I can’t find an answer. If anyone can help would appreciate it.

By the way, my problem is exactly the same as How do I override a Spring bean definition yet still reference the overridden bean? but I have yet to figure out how the author fixed it in the end (and there is also a suggestion that it’s not possible, which would make me very sad if true…!)

Thanks

  • 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-18T06:29:52+00:00Added an answer on May 18, 2026 at 6:29 am

    You can use a BeanPostProcessor based solution:

    public class AdditionalPropertiesBeanPostProcessor
    implements BeanPostProcessor{
    
        private Map<String, Map<String, Object>> propertiesMap;
    
        public void setPropertiesMap(
            final Map<String, Map<String, Object>> propertiesMap){
            this.propertiesMap = propertiesMap;
        }
    
        @Override
        public Object postProcessBeforeInitialization(final Object bean,
            final String beanName) throws BeansException{
            final Map<String, Object> props = propertiesMap.get(beanName);
            if(props != null){
                final BeanWrapper bw = new BeanWrapperImpl(bean);
                for(final Entry<String, Object> entry : props.entrySet()){
                    bw.setPropertyValue(entry.getKey(), entry.getValue());
                }
            }
            return bean;
        }
    
        @Override
        public Object postProcessAfterInitialization(final Object bean,
            final String beanName) throws BeansException{
            return bean;
        }
    
    }
    

    This is the bean definition:

    <bean class="foo.bar.AdditionalPropertiesBeanPostProcessor">
        <property name="propertiesMap">
            <map>
                <!-- Reference the bean by name -->
                <entry key="yourBeanName">
                    <map>
                        <!-- Supports Strings (and other standard types), -->
                        <entry key="propertyOne" value="abc" />
                        <!-- Bean references, -->
                        <entry key="service" value-ref="fooService" />
                        <!-- and inner beans -->
                        <entry key="someOtherProperty">
                            <bean class="foo.bar.SomeBean" />
                        </entry>
    
                    </map>
                </entry>
            </map>
        </property>
    </bean>
    

    Now all beans whose bean names can be found in your map will be populated with the additional properties you specified.

    I don’t know if this approach will work in all kinds of hierarchical context, but I verified that it works if the context that defines the Processor imports the other context.

    This solution does not apply to the other question, because that was about constructor injection. This solution only works with standard java bean properties.

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

Sidebar

Related Questions

No related questions found

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.