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
Try:
@Configuration
@ImportResource( { "spring-context1.xml", "spring-context2.xml" } )
public class ConfigClass { }
You need to add the classpath before the file name
@ImportResource(value = {
"classpath:file1.xml",
"classpath:file2.xml"
})
Just adding for future reference if anyone is using this in a groovy project.
In groovy the correct syntax uses [ ] square brackets . The curly braces will lead to compilation errors. Please find the example below.
@Configuration
@ImportResource( [ "spring-context1.xml", "spring-context2.xml" ] )
The correct format to define multiple spring resources spring xml context files using Spring 3 @ImportResource
:
@Configuration
@ImportResource( { "spring-context1.xml", "spring-context2.xml" } )
来源:https://stackoverflow.com/questions/15004674/spring-3-importresource-with-multiple-files