Over a million developers have joined DZone.

Grails Goodness: Get GrailsApplication and ApplicationContext in GSP

DZone's Guide to

Grails Goodness: Get GrailsApplication and ApplicationContext in GSP

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

Several variables are injected to Groovy Server Pages (GSP) in a Grails application. Two of them are the ApplicationContext and GrailsApplication objects. They are bound to the variables applicationContext and grailsApplication.

When we have access to the ApplicationContext we could for example load resources or get references to beans in the context. Via the grailsApplication variable we have access to for example the configuration values and metadata of the application.

<%-- File: grails-app/views/view/index.gsp --%>
        <title>GSP Sample</title>

            <dt># beans</dt>
            <dd>${applicationContext.beanDefinitionNames.join(', ')}</dd>



When we open this GSP in our browser we get the following output:


From http://mrhaki.blogspot.com/2011/11/grails-goodness-get-grailsapplication.html

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}