[英]Spring 3 @ImportResource with multiple files
I'm trying to find the syntax for importing multiple spring xml context files using Spring 3 @ImportResource annotation. 我正在尝试使用Spring 3 @ImportResource注释找到导入多个spring xml上下文文件的语法。
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." @ImportResource的文档说“表示包含要导入的bean定义的一个或多个资源”。 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 令人惊讶的是,我无法在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. 如果有人在一个groovy项目中使用它,只需添加以供将来参考。
In groovy the correct syntax uses [ ] square brackets . 在groovy中,正确的语法使用[]方括号 。 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
: 使用Spring 3 @ImportResource
定义多个spring资源spring xml上下文文件的正确格式:
@Configuration
@ImportResource( { "spring-context1.xml", "spring-context2.xml" } )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.