Accessing 'grailsApplication' from a plugin

grails, groovy

Solution

In services, you should be able to add

def grailsApplication

and it will be injected into your service.

If your class is a spring bean, then you should be able to inject it inside the

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

block of the plugin main groovy file.

If it's neither of these, have you tried using the Holders class?

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

Problem

How do I access "grailsApplication" of the main application from a plugin? An example situation: I have a class in a plugin, which needs to get a resource link from the main application, which is usually retrieved via "grailsApplication". How do I do that? SOLUTION In the plugin class you may simply specify: ``` import grails.util.Holders Holders.getGrailsApplication() ```

Original source

Related problems