{"id":1952,"date":"2010-10-15T01:25:26","date_gmt":"2010-10-14T19:55:26","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=1952"},"modified":"2010-10-15T01:25:26","modified_gmt":"2010-10-14T19:55:26","slug":"externalize-and-reload-grails-configuration-dynamically","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/","title":{"rendered":"Externalize and reload grails configuration dynamically"},"content":{"rendered":"<p>Configuration file plays great role in grails. You can store application specific configuration at one place. One of the grails goodies is that you can externalize configuration file i.e. store them at a location so that it is not packed with the war file.<br \/>\n<\/p>\n<p>Here is the part of Config.groovy that describes how to specify external configuration file :<\/p>\n<p>[groovy]<br \/>\n\/\/ configuration files can either be Java properties files or ConfigSlurper scripts.<br \/>\n\/\/Note that the file whose path is specified below is not included in war file.<\/p>\n<p>grails.config.locations = [&quot;file:${userHome}\/.myConfigurations\/${appName}-config.groovy&quot;]<br \/>\n[\/groovy]<\/p>\n<p>Externalizing the configuration helps us to change the configuration without re-creating the war file. But the problem I faced was changes to this external configuration file was not reloaded by grails automatically. I found the code to reload the configuration in <a href=\"http:\/\/grails.org\/plugin\/quartz\" target=\"_blank\">Grails Quartz plug-in<\/a> source code. Here is the code snippet.<\/p>\n<p>[groovy]<br \/>\n        def config = ConfigurationHolder.config<br \/>\n        GroovyClassLoader classLoader = new GroovyClassLoader(getClass().classLoader)<\/p>\n<p>        \/\/ merging default Quartz config into main application config<br \/>\n        config.merge(new ConfigSlurper(GrailsUtil.environment).parse(classLoader.loadClass(&#8216;DefaultQuartzConfig&#8217;)))<br \/>\n[\/groovy]<\/p>\n<p>However the code is reloading configuration from a groovy class(it should be in the class-path) that I could not use in my use case.<\/p>\n<p>Doing some googling and thanks to <a href=\"http:\/\/www.tothenew.com\/blog\/author\/himanshu\/\" target=\"_blank\">Himanshu<\/a> for useful code snippets, I found the constructor that accepts String . I used the following code to merge the changed external configuration file with the configuration of running application :<\/p>\n<p>[groovy]<br \/>\ndef config = ConfigurationHolder.config<br \/>\ndef locations = config.grails.config.locations<\/p>\n<p>locations.each {<br \/>\n\tString configFileName = it.split(&quot;file:&quot;)[1]<br \/>\n\tconfig.merge(new ConfigSlurper().parse(new File(configFileName).text))<br \/>\n}<br \/>\n\/\/above code iterates over all the external config files and<br \/>\n\/\/merges them with the running application configuration<br \/>\n[\/groovy]<\/p>\n<p>I wrote the above code inside a controller-action. Now whenever I change the external configuration file I simply hit the URL of the controller-action and the changes take effect that point onward. You can also use <a href=\"http:\/\/grails.org\/plugin\/console\" target=\"_blank\">Grails Console plug-in <\/a> that lets you execute groovy code from the running application or use <a href=\"http:\/\/grails.org\/plugin\/quartz\" target=\"_blank\">Grails Quartz Job<\/a> to periodically reload the external configuration.<br \/>\n<br \/>\nHope this helps you !<br \/>\n<br \/><strong><br \/>\n<em>Bhagwat Kumar<br \/>\nbhagwat(at)intelligrape(dot)com<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reloading configuration from external Configuration files without restarting the web container and putting the configuration file external to war file. I Used config.merge and new ConfigSlurper().parse( ) to merge the external configuration into the running application&#8217;s configuration<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":84,"footnotes":""},"categories":[7],"tags":[434,435,436,437,433],"class_list":["post-1952","post","type-post","status-publish","format-standard","hentry","category-grails","tag-config-groovy","tag-configslurper","tag-grails-config-locations","tag-merge-config","tag-reload-configuration"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Reloading configuration from external Configuration files without restarting the web container and putting the configuration file external to war file. I Used config.merge and new ConfigSlurper().parse( ) to merge the external configuration into the running application&#039;s configuration\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Bhagwat Kumar\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Externalize and reload grails configuration dynamically | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Reloading configuration from external Configuration files without restarting the web container and putting the configuration file external to war file. I Used config.merge and new ConfigSlurper().parse( ) to merge the external configuration into the running application&#039;s configuration\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Externalize and reload grails configuration dynamically | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Reloading configuration from external Configuration files without restarting the web container and putting the configuration file external to war file. I Used config.merge and new ConfigSlurper().parse( ) to merge the external configuration into the running application&#039;s configuration\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/externalize-and-reload-grails-configuration-dynamically\\\/#article\",\"name\":\"Externalize and reload grails configuration dynamically | TO THE NEW Blog\",\"headline\":\"Externalize and reload grails configuration dynamically\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bhagwat\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2010-10-15T01:25:26+05:30\",\"dateModified\":\"2010-10-15T01:25:26+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":9,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/externalize-and-reload-grails-configuration-dynamically\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/externalize-and-reload-grails-configuration-dynamically\\\/#webpage\"},\"articleSection\":\"Grails, Config.groovy, ConfigSlurper, grails.config.locations, merge config, reload configuration\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/externalize-and-reload-grails-configuration-dynamically\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"position\":2,\"name\":\"Grails\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/externalize-and-reload-grails-configuration-dynamically\\\/#listItem\",\"name\":\"Externalize and reload grails configuration dynamically\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/externalize-and-reload-grails-configuration-dynamically\\\/#listItem\",\"position\":3,\"name\":\"Externalize and reload grails configuration dynamically\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bhagwat\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bhagwat\\\/\",\"name\":\"Bhagwat Kumar\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/externalize-and-reload-grails-configuration-dynamically\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d6c506f803fe26906ef802b1eaee463146e449a8b5b3d1f7e4ebc715b933d620?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Bhagwat Kumar\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/externalize-and-reload-grails-configuration-dynamically\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/externalize-and-reload-grails-configuration-dynamically\\\/\",\"name\":\"Externalize and reload grails configuration dynamically | TO THE NEW Blog\",\"description\":\"Reloading configuration from external Configuration files without restarting the web container and putting the configuration file external to war file. I Used config.merge and new ConfigSlurper().parse( ) to merge the external configuration into the running application's configuration\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/externalize-and-reload-grails-configuration-dynamically\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bhagwat\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bhagwat\\\/#author\"},\"datePublished\":\"2010-10-15T01:25:26+05:30\",\"dateModified\":\"2010-10-15T01:25:26+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Externalize and reload grails configuration dynamically | TO THE NEW Blog","description":"Reloading configuration from external Configuration files without restarting the web container and putting the configuration file external to war file. I Used config.merge and new ConfigSlurper().parse( ) to merge the external configuration into the running application's configuration","canonical_url":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/#article","name":"Externalize and reload grails configuration dynamically | TO THE NEW Blog","headline":"Externalize and reload grails configuration dynamically","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/bhagwat\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2010-10-15T01:25:26+05:30","dateModified":"2010-10-15T01:25:26+05:30","inLanguage":"en-US","commentCount":9,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/#webpage"},"articleSection":"Grails, Config.groovy, ConfigSlurper, grails.config.locations, merge config, reload configuration"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","position":2,"name":"Grails","item":"https:\/\/www.tothenew.com\/blog\/category\/grails\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/#listItem","name":"Externalize and reload grails configuration dynamically"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/#listItem","position":3,"name":"Externalize and reload grails configuration dynamically","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/bhagwat\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/bhagwat\/","name":"Bhagwat Kumar","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d6c506f803fe26906ef802b1eaee463146e449a8b5b3d1f7e4ebc715b933d620?s=96&d=mm&r=g","width":96,"height":96,"caption":"Bhagwat Kumar"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/","name":"Externalize and reload grails configuration dynamically | TO THE NEW Blog","description":"Reloading configuration from external Configuration files without restarting the web container and putting the configuration file external to war file. I Used config.merge and new ConfigSlurper().parse( ) to merge the external configuration into the running application's configuration","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/bhagwat\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/bhagwat\/#author"},"datePublished":"2010-10-15T01:25:26+05:30","dateModified":"2010-10-15T01:25:26+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Externalize and reload grails configuration dynamically | TO THE NEW Blog","og:description":"Reloading configuration from external Configuration files without restarting the web container and putting the configuration file external to war file. I Used config.merge and new ConfigSlurper().parse( ) to merge the external configuration into the running application's configuration","og:url":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Externalize and reload grails configuration dynamically | TO THE NEW Blog","twitter:description":"Reloading configuration from external Configuration files without restarting the web container and putting the configuration file external to war file. I Used config.merge and new ConfigSlurper().parse( ) to merge the external configuration into the running application's configuration","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"1952","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 14:20:41","updated":"2024-02-29 09:09:22","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/grails\/\" title=\"Grails\">Grails<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tExternalize and reload grails configuration dynamically\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Grails","link":"https:\/\/www.tothenew.com\/blog\/category\/grails\/"},{"label":"Externalize and reload grails configuration dynamically","link":"https:\/\/www.tothenew.com\/blog\/externalize-and-reload-grails-configuration-dynamically\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1952","targetHints":{"allow":["GET"]}}],"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\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=1952"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1952\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=1952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=1952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=1952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}