Using Initialization bean to set properties

Using Grails, we often set some application wide constants or config properties or execute certain tasks in bootstrap.groovy when the application starts . A better approach is to create a new class in src/groovy and have it implement Initialization bean interface

import org.springframework.beans.factory.InitializingBean
class MyClass implements InitializingBean {
void afterPropertiesSet() {
        // do you stuff here.

Now in resources.groovy, add

myClass(MyClass) { bean ->
        bean.autowire = 'byName'

This would make it a spring managed bean and will be executed at the time the spring beans are initialized.
This is a no mess way of doing a task, while the application is coming up.


Sachin Anand


2 thoughts on “Using Initialization bean to set properties

  1. Pingback: An Army of Solipsists » Blog Archive » This Week in Grails (2012-33)

  2. Pingback: Questa settimana in Grails (2012-33) - - Il blog di Luca Canducci: notizie, tips e nuove tecnologie dal mondo dell’IT.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>