Reputation: 7196
I don't know,how to load multiple configuration files from classpath in spring using @ImportResource.I have already gone through the link Spring 3 @ImportResource with multiple files but no luck so far. My code is below.
@Configuration
@PropertySource("classpath:apis.application.properties")
@ComponentScan(basePackages = {"org.surfnet.oaaas.resource", "org.surfnet.oaaas.service"})
@ImportResource({"classpath:spring-repositories.xml,classpath:commonApplicationContext.xml"})
@EnableTransactionManagement
public class SpringConfiguration {
}
Exception i am facing is
java.io.FileNotFoundException: class path resource [spring-repositories.xml,classpath:commonApplicationContext.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
How ever when i try to load a single file,like below.it works for both file.But i can not include two ImportResource
annotation in a java class.
@ImportResource("classpath:spring-repositories.xml"})
Upvotes: 2
Views: 14252
Reputation: 206786
You are using the wrong syntax. Look carefully at how it's done in the question you linked to.
There are two strings, not one string containing names separated by commas:
@ImportResource({"classpath:spring-repositories.xml", "classpath:commonApplicationContext.xml"})
Upvotes: 5
Reputation: 11600
But you were almoust right:) It is simmilar like ComponentScan:
@ImportResource({"classpath:spring-repositories.xml","classpath:commonApplicationContext.xml"})
When you define resources inside {}, than you put each resource as separate String, optionally with file:, classpath: prefix.
I have found also this stack page:
Spring 3 @ImportResource with multiple files
Upvotes: 3