如果你想使用Grails提供的 Spring DSL ,你必须创建grailsapp/conf/spring/resources.groovy 文件,定义一个 beans属性块:beans = {
// 定义的beans
}
同样在的配置可以应用于XML例子:beans = {
myBean(my.company.MyBeanImpl) {
bookService = ref("bookService")
}
}这样做最大的好处是你能够在bean的定义中混合各种逻辑,如基于 environment:import grails.util.*
beans = {
switch(GrailsUtil.environment) {
case "production":
myBean(my.company.MyBeanImpl) {
bookService = ref("bookService")
}
break
case "development":
myBean(my.company.mock.MockImpl) {
bookService = ref("bookService")
}
break
}
}