Is there a way to get an ApplicationContext from contexts in the file system and the class path all at once? rather than using FileSystemXmlApplicationContext and then ClassPathXmlApplicationContext and passing the fileSystemApplicationContext as the parent?
+1
A:
I suggest you have a look at the org.springframework.context.support.GenericApplicationContext
. Together with an org.springframework.beans.factory.xml.XmlBeanDefinitionReader
it shoudl give you the flexibility you want. There is an example of code on the GenericApplicationContext
's javadoc
Your code would look like:
GenericApplicationContext ctx = new GenericApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
xmlReader.loadBeanDefinitions(new ClassPathResource("classpathContext.xml"));
xmlReader.loadBeanDefinitions(new FileSystemResource("fileSystemContext.xml"));
Note the XmlBeanDefinitionReader
also has a method loadBeanDefinitions(String)
which will then use org.springframework.core.io.ResourceLoader
to handle the appropriate resource. In which case your code would look like:
GenericApplicationContext ctx = new GenericApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
xmlReader.loadBeanDefinitions("classpath:classpathContext.xml"));
xmlReader.loadBeanDefinitions("file:fileSystemContext.xml"));
SaM
2009-11-07 05:54:30