Announcement Announcement Module
No announcement yet.
How to pass properties values to ClassPathXmlApplicationContext bean? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to pass properties values to ClassPathXmlApplicationContext bean?

    I have to use two beans with same id which defined in two separated jars from third party, so I basically cannot change the name. I decide to use ClassPathXmlApplicationContext to solve the conflict, e.g. in my applicationContext.xml, I define:

    <bean id="firstContext" class=" thXmlApplication">
    <bean id="firstService" class="org.springframwork.beans.factory.config.Bea nReferenceFactoryBean>
    <property name="targetBeanName">
    <property name="beanFactory"><ref="firstContext"></property>

    The problem is the commonService needs some configuration properties defined in our context, e.g., its constructor definition is like:
    <bean id="commonService>
    <property name="url"><value>http://$serviceHost:$servicePort/
    and we include a properties file in our applicationContext.xml like

    <bean class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location"> <value></value> </property>

    The properties have been successfully loaded (other beans in the applicationsContext.xml have been initialized with the correct value from the, but the commonService always throw an exception that http://$serviceHost:$servicePort/ is invalid. If I do not use the ClassPathXmlApplicationContext but just import the package1.xml, the commonService bean then can be initialized with the correct values (but I cannot import package2.xml since its commonSevice bean will override the first one). So the question is:

    1. Is there any better way to handle the conflict bean id WITHOUT modifying original definitions?
    2. How to pass the properties values from one application context to an other?

    Thanks in advance!