{"id":538,"date":"2010-04-15T13:59:42","date_gmt":"2010-04-15T08:29:42","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=538"},"modified":"2010-06-09T15:31:55","modified_gmt":"2010-06-09T10:01:55","slug":"injecting-spring-beans-with-data-from-config","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/injecting-spring-beans-with-data-from-config\/","title":{"rendered":"Injecting Spring Beans with data from Config"},"content":{"rendered":"<p>In one of the projects, we had to externalize the Config file to be in a <em>properties<\/em> file. All configurations related to the application were to be stored in that file. We had a few spring beans, like the JMS connection factory, which needs the brokerURL which should ideally be an external configuration as it is will be environment specific. An excellent approach to this issue could be seen in the mail plugin, wherein the bean is injected from config values.<\/p>\n<p>An example resource.groovy similar to that would be<\/p>\n<blockquote>\n<pre lang=\"groovy\">import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH\r\nbeans={\r\n   sampleBean(com.intelligrape.Sample){        \/\/Sample is a bean with a property value\r\n        value = CH.config.app.sample.value?:'defaultValue'\r\n                     \/\/app.sample.value is a property in the config.groovy file\r\n                     \/\/If no config property is specified, set to 'defaultValue'\r\n  }\r\n}<\/pre>\n<\/blockquote>\n<p>Hope this helps<\/p>\n<p>&#8211;Vivek<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of the projects, we had to externalize the Config file to be in a properties file. All configurations related to the application were to be stored in that file. We had a few spring beans, like the JMS connection factory, which needs the brokerURL which should ideally be an external configuration as it [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1},"categories":[7],"tags":[207,4840,9,4841],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/538"}],"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\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=538"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/538\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}