Reputation: 187499
I'm writing a Grails plugin that defines a Spring bean in the plugin descriptor
def doWithSpring = {
myBean(MyBean)
}
I need to get a reference to this bean from another class in the plugin.
class Something {
def doIt() {
// I need to get a reference to myBean here. Is this the best way?
MyBean myBean = ApplicationHolder.application.mainContext.getBean('myBean')
}
}
Something
is a class defined in src/groovy
within the same plugin as the bean, but Something
is not itself a spring bean. In Grails 1.3.7 is there a better way of achieving this than that shown above? I'm looking for a better way because I know the *Holder classes are deprecated in Grails 2.0
Upvotes: 2
Views: 3280
Reputation:
In Grails 2.x exists the Holders utility class to get the grailsApplication
and the applicationContext
.
In 1.3.7 I think the option is create your own holder, as described here.
Upvotes: 1