Access to "grailsApplication" from the plugin

How do I access the "grailsApplication" of the main application from the plugin?

An example of a situation: I have a class in a plugin that should get a link to a resource from the main application, which is usually retrieved through "grailsApplication". How to do it?

SOLUTION In the plugin class, you can simply specify:

import grails.util.Holders
Holders.getGrailsApplication()
+4
source share
1 answer

In services you can add

def grailsApplication

and it will be entered into your service.

If your class is a spring bean, you should be able to enter it inside

def doWithSpring = { ->
    myBean( org.whatever.BeanClass ) {
        grailsApplication = ref( 'grailsApplication' )
    }
}

block of the main groovy plugin file.

If this is not the case, do you try using the Holders class?

def grailsApplication = grails.util.Holders.getGrailsApplication()
+6

All Articles