Help me with this small confusion as I am new to grails and working on grails with spring
Is there any difference between ref to firstBean in secondBean and thirdBean in resources.groovy
beans = {
firstBean(someclass)
secondBean(someotherclass) {
property = firstBean
}
thirdBean(someotherclass) {
property = ref(firstBean)
}
}
In your example there is hardly any difference. You are getting basically the objects you just have defined there. So this only works, if you can order your code, so this works and if the refs are right within your resources.groovy
. The more common case is to use ref
with strings, which may "forward reference". Eg
beans = {
// fails! print b1
// fails! print ref(b1)
print ref("b1")
b1(Expando)
print b1
print ref(b1)
print ref("b1")
}
I'd use ref(<String>)
for good measure, to give the underlying spring injection framework the easiest way to handle its dependencies (eg so components need only to be created, if and when they are needed).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.