I'm trying to find the syntax for importing multiple spring xml context files using Spring 3 @ImportResource annotation.
I have tried using comma to separate the filenames as illustrated below but that does not work:
@Configuration @ImportResource("spring-context1.xml", "spring-context2.xml") public class ConfigClass { }
The doc for @ImportResource says "Indicates one or more resources containing bean definitions to import." so I believe there should be a way to specify multiple context files. Surprisingly, I've not been able to find any example on Google
You can group multiple configurations in @Import and @ImportResource annotations. In the previous example, we have used only single class and single xml config files inside these annotations.
Yes, in large projects, having multiple Spring configurations increase maintainability and modularity. You can also upload one XML file that will contain all configs.
You may load multiple Spring bean configuration files in the code : ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"Spring-Common. xml", "Spring-Connection. xml","Spring-ModuleA.
Try:
@Configuration @ImportResource( { "spring-context1.xml", "spring-context2.xml" } ) public class ConfigClass { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With