Reputation: 187399
According to the docs the GrailsApplicationAware
interface is a
Convenience interface that can be implemented by classes that are registered by plugins.
So presumably a Spring bean that implements this interface can use it to get an instance of GrailsApplication
. But can other objects implement this interface for the same purpose? It's not clear to me what is meant by
classes that are registered by plugins
Upvotes: 0
Views: 800
Reputation: 122414
It works the same as standard Spring interfaces such as ApplicationContextAware
- any bean (whether implicitly registered as an artefact or explicitly registered in resources.xml
, resources.groovy
or a plugin's doWithSpring
) that implements the interface will have its setGrailsApplication(GrailsApplication ga)
method called automatically by the framework without needing to explicitly name it as a property or turn on autowiring.
For beans that are set up to do autowiring (e.g. Grails services) you don't need to implement GrailsApplicationAware
, you only need to provide a setGrailsApplication
method (which a Groovy property definition def grailsApplication
will create for you) and it will be autowired because the GrailsApplication
is registered as a bean named grailsApplication
. Or of course you can inject the bean explicitly
doWithSpring = {
myPluginBean(MyPluginBean) {
grailsApplication = ref('grailsApplication')
}
}
Upvotes: 4