我正在尝试使用Groovy配置我的Spring应用程序。我有几个模块,因此整个上下文被拆分为几个.groovy
文件。Spring Groovy配置:导入ConfigSlurper属性
我用suggested method(部分使用外部属性)读取使用ConfigSlurper,从外部文件属性,以便在我的主要context.groovy
有定义和使用props
对象:
def props = new ConfigSlurper("dev").parse("app.properties")
beans {
someBean(SomeBean) {
commonShinyProperty = props.common.shiny
}
}
其中app.properties
是:
common {
shiny = true
}
我想要做的是重用相同的属性源代码E(props
对象)在另一个上下文部分anotherContext.groovy
- 是这样的:
importBeans('classpath:context.groovy')
beans {
anotherBean(AnotherBean) {
commonShinyProperty = props.common.shiny
}
}
此代码不作为props
工作是不是可以在这里找到,从context.groovy
只有豆子。即使它被定义为豆,应用程序无法启动,如Cannot get property 'shiny' on null object
或No such property: for class...
请建议,如果这样的配置是可能的。先谢谢你!
谢谢你,@davidiamyou。 – 2015-02-14 09:58:00