title: Datasource.groovy executed prior to application context loading?
body: <p>I'm trying to implement a codec to decrypt a password for an Oracle data connection.  The codec will be used in various locations, and I thought it might be a good idea to create a plugin for it.  My idea was to create a codec that was aware of the Spring context, and could pull its salt phrase from <strong>Config.groovy</strong>.  I have the Codec coded, and it's connecting at application startup - but it appears that my <code>SpringContext.getApplicationContext()</code> is returning null when the application starts up.  I'm assuming this is because the application context hasn't been initialized yet - but my research isn't telling me much on the load order yet.</p>
  
  <p>If that's the case, how would one go about externalizing something like this in configuration?  The only way I know of to access <strong>DataSource</strong> information is through items like the <code>grailsApplication</code> reference (again Spring dependent).</p>
  
  <p>Slightly Sanitized Code Snippet:</p>
  
  <pre><code>static Codec getCodec(){
      if( !SpringContext.getApplicationContext() ){
         println "Context Is Null"
      }
      def config = SpringContext?.getApplicationContext()?.
                                  getBean("grailsApplication")?.config?.crypto
      String saltValue = config?.salt
      ...
  </code></pre>
  
  <p>Datasource.groovy is setup thusly:</p>
  
  <pre><code>datasource {
      ...some stuff
      passwordEncryptionCodec = 'com.someguy.mycode.StaticCodec'
  </code></pre>
  
  <p>Inside StaticCodec, I basically have encode/decode methods that call the factory method in the first code sample, they execute with no problem - and I receive the "Context Is Null" statement printed in the startup log after executing run-app.</p>
  
  <p><strong>SpringContext</strong> is a bean I've created in the <code>doWithSpring</code> section of my plugin, and seems to work fine outside of this startup issue (accessing the codec at request time works perfectly).</p>
  
  <p>I had assumed the Spring container would be the first thing up and running when the application  launched - am I wrong in this?  Is there some other reason why the application context would be null when data sources are setting up at launch?</p>