> On Apr 17, 2015, at 10:03 PM, Bud Byrd <
bud....@gmail.com> wrote:
>
> I'm sorry for not making my ask clear. I'm speaking of the Application.groovy file located in grails-app/init, for grails applications (not plugins). We now have the ability to use the same startup hooks in applications as we do in plugins (such as doWithSpring, etc). I'd like to use these methods instead of relying on the spring resources file, but I can not find a way to use the application configuration in this file.
>
> The Application.groovy file extends GrailsAutoConfiguration.
>
> Thanks for any help!
It really depends on what it is you want to do with the config values. One thing you can do is refer to grails.util.Holders.config but that may not really be the best thing to do. The best solution depends on details you haven't provided but just as an example...
In your Application.doWithSpring method you could create the bean as per usual without any reference to the config and have the bean configure itself at post processing time.
// grails-app/init/myapp/Application.groovy
package myapp
import grails.boot.GrailsApp
import grails.boot.config.GrailsAutoConfiguration
class Application extends GrailsAutoConfiguration {
@Override
Closure doWithSpring() {{ ->
// create a bean...
someBeanName demo.SomeBean
}}
static void main(String[] args) {
GrailsApp.run(Application)
}
}
// src/main/groovy/demo/SomeBean.groovy
package demo
import grails.core.support.GrailsApplicationAware
import grails.core.GrailsApplication
class SomeBean implements GrailsApplicationAware {
GrailsApplication grailsApplication
String someStringConfigValue
void setGrailsApplication(GrailsApplication ga) {
def config = ga.config
// do whatever you want to do with the config here, for example…
someStringConfigValue = config.foo.bar.bing.baz
}
}
You could also write a bean post processor if you need to interact with a bunch of different beans. You have a number of options and knowing which one is best depends on what it is you are really trying to do.
It may be that we should look at providing direct access to the config in Application.doWithSpring, or maybe there is already a path there that I am overlooking.
I don't know if that is really going to help or not.