{"id":6178,"date":"2012-08-14T15:28:42","date_gmt":"2012-08-14T09:58:42","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=6178"},"modified":"2012-08-24T09:20:44","modified_gmt":"2012-08-24T03:50:44","slug":"using-initialization-bean-to-set-properties","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/using-initialization-bean-to-set-properties\/","title":{"rendered":"Using Initialization bean to set properties"},"content":{"rendered":"<p>Using Grails, we often set some application wide constants or config properties or execute certain tasks in bootstrap.groovy\u00a0when the application starts .\u00a0A better approach is to create a new class in src\/groovy and have it implement Initialization bean\u00a0interface<\/p>\n<p>[java]<br \/>\nimport org.springframework.beans.factory.InitializingBean<br \/>\nclass MyClass implements InitializingBean {<br \/>\nvoid afterPropertiesSet() {<br \/>\n        \/\/ do you stuff here.<br \/>\n    }<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>Now in resources.groovy, add<\/p>\n<p>[java]<br \/>\nmyClass(MyClass) { bean -&gt;<br \/>\n        bean.autowire = &#8216;byName&#8217;<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>This would make it a spring managed bean and will be executed at the time the spring beans are initialized.<br \/>\nThis is a no mess way of doing a task, while the application is coming up.<\/p>\n<p>Thanks<\/p>\n<p>Sachin Anand<\/p>\n<p><span style=\"text-decoration: line-through;\">sachin@intelligrape.com<\/span><\/p>\n<p><span style=\"text-decoration: line-through;\">@babasachinanand<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Grails, we often set some application wide constants or config properties or execute certain tasks in bootstrap.groovy\u00a0when the application starts .\u00a0A better approach is to create a new class in src\/groovy and have it implement Initialization bean\u00a0interface [java] import org.springframework.beans.factory.InitializingBean class MyClass implements InitializingBean { void afterPropertiesSet() { \/\/ do you stuff here. } [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[7],"tags":[178,862,864,863],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/6178"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=6178"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/6178\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=6178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=6178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=6178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}