Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring 3 @ImportResource with multiple files

Tags:

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

like image 327
Kes115 Avatar asked Feb 21 '13 14:02

Kes115


People also ask

How can you create an application context from multiple files which annotation can you used to combine multiple configuration files?

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.

Can the configuration of Spring beans be defined in multiple XML files for one application context?

Yes, in large projects, having multiple Spring configurations increase maintainability and modularity. You can also upload one XML file that will contain all configs.

How can we load all the bean configuration files?

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.


1 Answers

Try:

@Configuration   @ImportResource( { "spring-context1.xml", "spring-context2.xml" } )   public class ConfigClass { }   
like image 116
ajames Avatar answered Oct 19 '22 14:10

ajames