I have a Spring bean defined in an xml file. I want to reference it from another xml file. How can I go about it?
You have a couple of options:
ApplicationContext ConstructionMake both files a part of your ApplicationContext when you create it => then no import is needed.
For example if you need it during testing:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:META-INF/conf/spring/this-xml-conf.xml",
"classpath:META-INF/conf/spring/that-other-xml-conf.xml" })
public class CleverMoneyMakingBusinessServiceIntegrationTest {...}
In case it is a web app, you'd do it in web.xml:
contextConfigLocation
WEB-INF/conf/spring/this-xml-conf.xml
WEB-INF/conf/spring/that-other-xml-conf.xml
org.springframework.web.context.ContextLoaderListener
If it is a stand alone app, library, etc.. you would load your ApplicationContext as:
new ClassPathXmlApplicationContext(
new String[] { "classpath:META-INF/conf/spring/this-xml-conf.xml",
"classpath:META-INF/conf/spring/that-other-xml-conf.xml" } );