Using Initialization bean to set properties

14 / Aug / 2012 by Sachin 0 comments

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



Leave a Reply

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