Spring 3 @ImportResource with multiple files

Kes115 picture Kes115 · Feb 21, 2013 · Viewed 58.2k times · Source

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

Answer

ajames picture ajames · Feb 26, 2013

Try:

@Configuration  
@ImportResource( { "spring-context1.xml", "spring-context2.xml" } )  
public class ConfigClass { }