2

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"})
Community
  • 1
  • 1
dReAmEr
  • 6,986
  • 7
  • 36
  • 63

2 Answers2

5

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"})
Jesper
  • 202,709
  • 46
  • 318
  • 350
3

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

Community
  • 1
  • 1
Beri
  • 11,470
  • 4
  • 35
  • 57