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.
Thanks
Sachin Anand
sachin@intelligrape.com
@babasachinanand
This entry was posted
on August 14th, 2012
at
3:28 pm and is filed under
Grails .
You can follow any responses to this entry through the
RSS 2.0 feed.
You can leave a response, or trackback from your own site.

[...] Using Initialization bean to set properties [...]
[...] Using Initialization bean to set properties [...]