How to load multiple configuration file from classpath using @ImportResource annotation in Spring

dReAmEr

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"})
Jesper

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"})

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Primary spring bean overridden by ImportResource in Configuration

@ConfigurationProperties Spring Boot Configuration Annotation Processor not found in classpath

@ConfigurationProperties Spring Boot Configuration Annotation Processor not found in classpath

How Spring finds the XSD file from classpath

How to go from XML Spring scheduling configuration to annotation/code configuration?

Spring-boot thymeleaf load HTML file from classpath

Spring 3 @ImportResource with multiple files

Reading a List from properties file and load with spring annotation @Value

How to configure MappingJacksonHttpMessageConverter while using spring annotation-based configuration?

How to load multiple configuration files using apache common configuration(java)

load a (xml) file from the classpath in a spring web app

How to configure for Spring Boot Configuration Annotation Processor using @ConfigurationProperties on IntelliJ?

Spring - Using Value annotation to read from the local config file

Spring / Maven load file from classpath

How to load spring data jpa's database configuration from a external file?

Spring annotation value from configuration

annotation - How load Spring configuration class?

how to load additional bean configuration file in spring at run time

How to load property file from classpath in AWS lambda java

Load Values from configuration File using spring

how to load map from properties file with spring

How spring load configuration file by environment?

how to load an xmodmap configuration file using .xinitrc

How to load a properties file from classpath in Java

Load file from classpath using OPCPackage in OSGi environment

Do we need xml file for doing Spring configuration using Annotation?

How to load ICC profile from classpath?

How to generate db schema from entities using annotation configuration?

Spring-Boot: How to load a keystore resource file either from the classpath or from the file system?