title: Grails - access static config object in codec class
body: <p>I am currently updating my Grails project in order not to use the deprecated ConfigurationHolder class.
  This goes fine in most cases, but I am facing trouble in my custom codec classes, where I have been using the following approach until now:</p>
  
  <pre><code>import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH
  class MyCodec {
  
      static boolean myStaticConfigProperty=CH.config.myStaticConfigProperty
  
      static encode = { something -&gt;
         if(myStaticConfigProperty)
            ...
      }
  
  }
  </code></pre>
  
  <p>Direct injection using</p>
  
  <pre><code>def grailsApplication 
  </code></pre>
  
  <p>does not work in this case since this will be injected as a non-static object.</p>
  
  <p>Instead I have tried to use the approach suggested in this post <a href="https://stackoverflow.com/questions/6976983/getting-grails-2-0-0m1-config-info-in-domain-object-and-static-scope">getting-grails-2-0-0m1-config-info-in-domain-object-and-static-scope</a>, but I cannot make it work even after injecting the grailsApplication object into my codec metaclasses in the bootstrap:</p>
  
  <pre><code>class BootStrap {
  
     def grailsApplication
  
     def init = { servletContext -&gt;
        for (cc in grailsApplication.codecClasses) {
           cc.clazz.metaClass.getGrailsApplication = { -&gt; grailsApplication }
           cc.clazz.metaClass.static.getGrailsApplication = { -&gt; grailsApplication }
        }      
     }
  }
  </code></pre>
  
  <p>Could anyone suggest an approach that will allow me to access the config object in a static way inside codec classes?</p>