grails:spring:resources.groovy - 使用和不使用 ref() 来引用 bean 之间有什么区别吗
grails:spring:resources.groovy - is there any difference between refrencing beans with and without ref()
帮助我解决这个小困惑,因为我是 grails 的新手并且正在使用 spring
处理 grails
secondBean 中的 firstBean 和 resources.groovy 中的 thirdBean 的 ref 有什么区别
beans = {
firstBean(someclass)
secondBean(someotherclass) {
property = firstBean
}
thirdBean(someotherclass) {
property = ref(firstBean)
}
}
在你的例子中几乎没有任何区别。你基本上得到了你刚刚在那里定义的对象。所以这只有在你可以订购你的代码时才有效,所以这有效并且如果引用在你的 resources.groovy
中。更常见的情况是对字符串使用 ref
,可能 "forward reference"。例如
beans = {
// fails! print b1
// fails! print ref(b1)
print ref("b1")
b1(Expando)
print b1
print ref(b1)
print ref("b1")
}
我会使用 ref(<String>)
作为一个很好的衡量标准,为底层 spring 注入框架提供处理其依赖项的最简单方法(例如,因此只需要创建组件,如果它们何时创建需要)。
帮助我解决这个小困惑,因为我是 grails 的新手并且正在使用 spring
处理 grailssecondBean 中的 firstBean 和 resources.groovy 中的 thirdBean 的 ref 有什么区别
beans = {
firstBean(someclass)
secondBean(someotherclass) {
property = firstBean
}
thirdBean(someotherclass) {
property = ref(firstBean)
}
}
在你的例子中几乎没有任何区别。你基本上得到了你刚刚在那里定义的对象。所以这只有在你可以订购你的代码时才有效,所以这有效并且如果引用在你的 resources.groovy
中。更常见的情况是对字符串使用 ref
,可能 "forward reference"。例如
beans = {
// fails! print b1
// fails! print ref(b1)
print ref("b1")
b1(Expando)
print b1
print ref(b1)
print ref("b1")
}
我会使用 ref(<String>)
作为一个很好的衡量标准,为底层 spring 注入框架提供处理其依赖项的最简单方法(例如,因此只需要创建组件,如果它们何时创建需要)。