Externalize application properties in a Grails app

03 / Sep / 2008 by Deepak 2 comments

Externalizing properties of an application has really come a long way, especially if you are using Grails.

Just want to share as a quick tip how easy it is to externalize the properties in a Grails application.

This is what all we have to do in-order to get something from a properties file.

In config.groovy include the properties that you want to be outside your groovy code.

For Example :

smtpUserName = "<someid@test.com>"
hostname = "yourHostName"

In order to read these properties in your Grails controller:

def smtpUserName = grailsApplication.config.smtpUserName

In order to read the properties from Grails Service class:

def smtpUserName =  ConfigurationHolder.config.smtpUserName

Easy, isn’t it?

Tag -

Grails Groovy
FOUND THIS USEFUL? SHARE IT

comments (2)

  1. jux.com

    When I initially commented I clicked the “Notify me when new comments are added” checkbox
    andd now eqch time a comment iis added I get several emails
    with the same comment. Is there any way you can remove
    me from that service? Thank you!

    Review my wweb page: Business Engagement (jux.com)

    Reply

Leave a comment -