我不知道如何在春季使用@ImportResource从类路径中加载多个配置文件。到目前为止,我已经通过了Spring 3 @ImportResource链接, 其中包含多个文件,但到目前为止还没有运气。我的代码如下。
@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 {
}
Run Code Online (Sandbox Code Playgroud)
我面临的例外是
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)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试加载单个文件时,如下所示。它对两个文件都适用。但是我不能ImportResource在Java类中包含两个注释。
@ImportResource("classpath:spring-repositories.xml"})
Run Code Online (Sandbox Code Playgroud)
您使用了错误的语法。仔细查看所链接问题中的处理方式。
有两个字符串,而不是一个包含用逗号分隔的名称的字符串:
@ImportResource({"classpath:spring-repositories.xml", "classpath:commonApplicationContext.xml"})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11760 次 |
| 最近记录: |