Our project has two application contexts:
- application-context.xml
- application-context-test.xml
Currently each file has duplicate bean definitions. So for example the following bean would be in each application context:
<bean id="foo "class="com.foo">
<property name="bar">
<ref local="bar"/>
</property>
</bean>
The plan is to create another file for bean definitions so we can reuse the beans, however, if we put the above xml segment into its own file, there will be no reference to bar
Is there an easy way to solve this?
Please note that barwill be different in each application context.
Thanks!
<ref local="bar"/>has a specific meaning – it means thatbarmust be defined in the same file. In your case, that’s too strict, so loosen it a bit:And then use
<import resource="...">to import this file where needed.With this,
barmust still exist, but it can be in any file that’s part of the context, or in any of the parent contexts.