Quantcast

Grails 3 - External config

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Grails 3 - External config

Benoit HEDIARD
Hi,

In the new Grails 3 documentation, there is no "Externalized configuration" info.
I tried to create an application.groovy and use grails.config.locations without success ;).

Is grails.config.locations not supported anymore?
What would be the equivalent?

Thanks!

Benoit

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/5113725b-7302-4988-b908-d031dbc23cb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

Graeme Rocher-2
Grails 3 uses Spring's property sources concept, so it will resolve
properties from the system, the environment and finally the
application.yml/application.groovy

So if you need to externalise configuration you can do so simply be
settings system or environment variables. Alternatively you can define
a different property source in your 'Application' class as follows
(untested pseudo code):


class Application extends GrailsAutoConfiguration implements EnvironmentAware {
     @Override
     void Environment(Environment env) {
            def res =
getClass().classLoader.getResource('myConfig.groovy')  // file in
grails-app/conf or loaded from where ever
            if(res) {
                  def config = new ConfigSlurper().parse( res )
                  env.propertySources.addFirst( new MapPropertySource(config) )
            }
     }
}

On Sun, Mar 8, 2015 at 11:30 PM, Benoit Hediard <[hidden email]> wrote:

> Hi,
>
> In the new Grails 3 documentation, there is no "Externalized configuration"
> info.
> I tried to create an application.groovy and use grails.config.locations
> without success ;).
>
> Is grails.config.locations not supported anymore?
> What would be the equivalent?
>
> Thanks!
>
> Benoit
>
> --
> You received this message because you are subscribed to the Google Groups
> "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/grails-dev-discuss/5113725b-7302-4988-b908-d031dbc23cb5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Graeme Rocher

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAO_wNodw9bFZ92aKm6rEtaxDup-tj%2BUZoKHHMvBhyTCqrSCMPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

Benoit HEDIARD
That’s great!
I’ll give it a try.

Thanks

Le 9 mars 2015 à 08:54, Graeme Rocher <[hidden email]> a écrit :

Grails 3 uses Spring's property sources concept, so it will resolve
properties from the system, the environment and finally the
application.yml/application.groovy

So if you need to externalise configuration you can do so simply be
settings system or environment variables. Alternatively you can define
a different property source in your 'Application' class as follows
(untested pseudo code):


class Application extends GrailsAutoConfiguration implements EnvironmentAware {
    @Override
    void Environment(Environment env) {
           def res =
getClass().classLoader.getResource('myConfig.groovy')  // file in
grails-app/conf or loaded from where ever
           if(res) {
                 def config = new ConfigSlurper().parse( res )
                 env.propertySources.addFirst( new MapPropertySource(config) )
           }
    }
}

On Sun, Mar 8, 2015 at 11:30 PM, Benoit Hediard <[hidden email]> wrote:
Hi,

In the new Grails 3 documentation, there is no "Externalized configuration"
info.
I tried to create an application.groovy and use grails.config.locations
without success ;).

Is grails.config.locations not supported anymore?
What would be the equivalent?

Thanks!

Benoit

--
You received this message because you are subscribed to the Google Groups
"Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit
https://groups.google.com/d/msgid/grails-dev-discuss/5113725b-7302-4988-b908-d031dbc23cb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



-- 
Graeme Rocher

-- 
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/_5VtFz4SpDY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAO_wNodw9bFZ92aKm6rEtaxDup-tj%2BUZoKHHMvBhyTCqrSCMPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/20D2744C-6874-4912-A90A-68CC34530F7E%40benorama.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

Ronny Løvtangen
In reply to this post by Graeme Rocher-2
BTW; is there a list of features that won't make it from Grails 2.x to 3.x?
Would be handy to figure out if an application could be easily upgraded or not.

The external config support is one issue that will affect all our applications, hopefully the pseudo code provided will work.

Ronny Løvtangen

> On 09 Mar 2015, at 08:54, Graeme Rocher <[hidden email]> wrote:
>
> Grails 3 uses Spring's property sources concept, so it will resolve
> properties from the system, the environment and finally the
> application.yml/application.groovy
>
> So if you need to externalise configuration you can do so simply be
> settings system or environment variables. Alternatively you can define
> a different property source in your 'Application' class as follows
> (untested pseudo code):
>
>
> class Application extends GrailsAutoConfiguration implements EnvironmentAware {
>     @Override
>     void Environment(Environment env) {
>            def res =
> getClass().classLoader.getResource('myConfig.groovy')  // file in
> grails-app/conf or loaded from where ever
>            if(res) {
>                  def config = new ConfigSlurper().parse( res )
>                  env.propertySources.addFirst( new MapPropertySource(config) )
>            }
>     }
> }
>
> On Sun, Mar 8, 2015 at 11:30 PM, Benoit Hediard <[hidden email]> wrote:
>> Hi,
>>
>> In the new Grails 3 documentation, there is no "Externalized configuration"
>> info.
>> I tried to create an application.groovy and use grails.config.locations
>> without success ;).
>>
>> Is grails.config.locations not supported anymore?
>> What would be the equivalent?
>>
>> Thanks!
>>
>> Benoit
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Grails Dev Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [hidden email].
>> To post to this group, send email to [hidden email].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/grails-dev-discuss/5113725b-7302-4988-b908-d031dbc23cb5%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Graeme Rocher
>
> --
> You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAO_wNodw9bFZ92aKm6rEtaxDup-tj%2BUZoKHHMvBhyTCqrSCMPA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/C61D259A-A980-416D-91B9-63B382A19712%40lovtangen.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

Clyde Balneaves
In reply to this post by Benoit HEDIARD
Pseudo to working code:

class Application extends GrailsAutoConfiguration implements EnvironmentAware {
    static void main(String[] args) {
        GrailsApp.run(Application)
    }

    @Override
    void setEnvironment(Environment environment) {
        //Set up Configuration directory
        def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken"

        println ""
        println "Loading configuration from ${krakenHome}"
        def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists()
        println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}"
        println "Config file found : " + appConfigured

        if (appConfigured) {
            def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL())
            environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config))
        }
    }
}

On Sunday, March 8, 2015 at 5:30:52 PM UTC-5, Benoit Hediard wrote:
Hi,

In the new Grails 3 documentation, there is no "Externalized configuration" info.
I tried to create an application.groovy and use grails.config.locations without success ;).

Is grails.config.locations not supported anymore?
What would be the equivalent?

Thanks!

Benoit

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/c197d8ea-c767-4dc5-a25c-b53867e976d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

Michael Baehr-3
Thanks Clyde, I was running into the same problem, and your code works.

It seems though that the environment{} logic is not supported - I don't see any configuration parameters that are defined inside the environment block. Do you have any idea how this can be enabled?

Thanks

Michael

On Friday, March 27, 2015 at 8:39:22 AM UTC-5, Clyde Balneaves wrote:
Pseudo to working code:

class Application extends GrailsAutoConfiguration implements EnvironmentAware {
    static void main(String[] args) {
        GrailsApp.run(Application)
    }

    @Override
    void setEnvironment(Environment environment) {
        //Set up Configuration directory
        def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken"

        println ""
        println "Loading configuration from ${krakenHome}"
        def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists()
        println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}"
        println "Config file found : " + appConfigured

        if (appConfigured) {
            def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL())
            environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config))
        }
    }
}

On Sunday, March 8, 2015 at 5:30:52 PM UTC-5, Benoit Hediard wrote:
Hi,

In the new Grails 3 documentation, there is no "Externalized configuration" info.
I tried to create an application.groovy and use grails.config.locations without success ;).

Is grails.config.locations not supported anymore?
What would be the equivalent?

Thanks!

Benoit

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/f611849d-3e01-4dfc-a299-d030845d7719%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

Clyde Balneaves
Do you mean different logic depending on whether you are running in development or production mode?  I havent tried it (just started my port to Grails 3) but this is all I could find to do it from within the Application class.  Sorry for the slow reply, I should check gmail more often!

import grails.util.Environment

...

switch (Environment.current) { case Environment.DEVELOPMENT: configureForDevelopment() break case Environment.PRODUCTION: configureForProduction() break }


On Thursday, April 2, 2015 at 7:10:27 PM UTC-5, Michael Baehr wrote:
Thanks Clyde, I was running into the same problem, and your code works.

It seems though that the environment{} logic is not supported - I don't see any configuration parameters that are defined inside the environment block. Do you have any idea how this can be enabled?

Thanks

Michael

On Friday, March 27, 2015 at 8:39:22 AM UTC-5, Clyde Balneaves wrote:
Pseudo to working code:

class Application extends GrailsAutoConfiguration implements EnvironmentAware {
    static void main(String[] args) {
        GrailsApp.run(Application)
    }

    @Override
    void setEnvironment(Environment environment) {
        //Set up Configuration directory
        def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken"

        println ""
        println "Loading configuration from ${krakenHome}"
        def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists()
        println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}"
        println "Config file found : " + appConfigured

        if (appConfigured) {
            def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL())
            environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config))
        }
    }
}

On Sunday, March 8, 2015 at 5:30:52 PM UTC-5, Benoit Hediard wrote:
Hi,

In the new Grails 3 documentation, there is no "Externalized configuration" info.
I tried to create an application.groovy and use grails.config.locations without success ;).

Is grails.config.locations not supported anymore?
What would be the equivalent?

Thanks!

Benoit

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/3f32b293-ae77-4c8a-abdc-5b2b52863d25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

Clyde Balneaves
In reply to this post by Michael Baehr-3
Of course if you meant the external config has environment specific properties, then I have no idea!  I've been loading different files based on the logic, or getting Puppet to modify the file based on the environment.

On Thursday, April 2, 2015 at 7:10:27 PM UTC-5, Michael Baehr wrote:
Thanks Clyde, I was running into the same problem, and your code works.

It seems though that the environment{} logic is not supported - I don't see any configuration parameters that are defined inside the environment block. Do you have any idea how this can be enabled?

Thanks

Michael

On Friday, March 27, 2015 at 8:39:22 AM UTC-5, Clyde Balneaves wrote:
Pseudo to working code:

class Application extends GrailsAutoConfiguration implements EnvironmentAware {
    static void main(String[] args) {
        GrailsApp.run(Application)
    }

    @Override
    void setEnvironment(Environment environment) {
        //Set up Configuration directory
        def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken"

        println ""
        println "Loading configuration from ${krakenHome}"
        def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists()
        println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}"
        println "Config file found : " + appConfigured

        if (appConfigured) {
            def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL())
            environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config))
        }
    }
}

On Sunday, March 8, 2015 at 5:30:52 PM UTC-5, Benoit Hediard wrote:
Hi,

In the new Grails 3 documentation, there is no "Externalized configuration" info.
I tried to create an application.groovy and use grails.config.locations without success ;).

Is grails.config.locations not supported anymore?
What would be the equivalent?

Thanks!

Benoit

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/58320364-f83a-494b-b215-a646c067bd51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

Michael Baehr-3
Yeah, environment specific properties is what I'm after. I'm also converting a production application to Grails 3, and I'm not sure if there are customers out there who have environment blocks in their configs. Guess I will have to find out the hard way ... ;)

Thanks for your support, your code was already very helpful!

On Monday, April 6, 2015 at 8:15:13 AM UTC-5, Clyde Balneaves wrote:
Of course if you meant the external config has environment specific properties, then I have no idea!  I've been loading different files based on the logic, or getting Puppet to modify the file based on the environment.

On Thursday, April 2, 2015 at 7:10:27 PM UTC-5, Michael Baehr wrote:
Thanks Clyde, I was running into the same problem, and your code works.

It seems though that the environment{} logic is not supported - I don't see any configuration parameters that are defined inside the environment block. Do you have any idea how this can be enabled?

Thanks

Michael

On Friday, March 27, 2015 at 8:39:22 AM UTC-5, Clyde Balneaves wrote:
Pseudo to working code:

class Application extends GrailsAutoConfiguration implements EnvironmentAware {
    static void main(String[] args) {
        GrailsApp.run(Application)
    }

    @Override
    void setEnvironment(Environment environment) {
        //Set up Configuration directory
        def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken"

        println ""
        println "Loading configuration from ${krakenHome}"
        def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists()
        println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}"
        println "Config file found : " + appConfigured

        if (appConfigured) {
            def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL())
            environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config))
        }
    }
}

On Sunday, March 8, 2015 at 5:30:52 PM UTC-5, Benoit Hediard wrote:
Hi,

In the new Grails 3 documentation, there is no "Externalized configuration" info.
I tried to create an application.groovy and use grails.config.locations without success ;).

Is grails.config.locations not supported anymore?
What would be the equivalent?

Thanks!

Benoit

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/26fbe576-1c9d-4328-b6e1-357cfc4fe531%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

Peyman P
here a yml version. it works for me:

class Application extends GrailsAutoConfiguration implements EnvironmentAware {
static void main(String[] args) {
GrailsApp.run(Application)
}

@Override
void setEnvironment(Environment environment) {
String configPath = System.properties["appname.config.location"]
Resource resourceConfig = new FileSystemResource(configPath);
YamlPropertiesFactoryBean ypfb = new YamlPropertiesFactoryBean();
ypfb.setResources(resourceConfig);
ypfb.afterPropertiesSet();
Properties properties = ypfb.getObject();
environment.propertySources.addFirst(new PropertiesPropertySource("appname.config.location", properties))
}
}

build.gradle

bootRun {
jvmArgs = ['-Dappname.config.location=/path/to/config.yml']
}



Am Montag, 6. April 2015 19:15:38 UTC+2 schrieb Michael Baehr:
Yeah, environment specific properties is what I'm after. I'm also converting a production application to Grails 3, and I'm not sure if there are customers out there who have environment blocks in their configs. Guess I will have to find out the hard way ... ;)

Thanks for your support, your code was already very helpful!

On Monday, April 6, 2015 at 8:15:13 AM UTC-5, Clyde Balneaves wrote:
Of course if you meant the external config has environment specific properties, then I have no idea!  I've been loading different files based on the logic, or getting Puppet to modify the file based on the environment.

On Thursday, April 2, 2015 at 7:10:27 PM UTC-5, Michael Baehr wrote:
Thanks Clyde, I was running into the same problem, and your code works.

It seems though that the environment{} logic is not supported - I don't see any configuration parameters that are defined inside the environment block. Do you have any idea how this can be enabled?

Thanks

Michael

On Friday, March 27, 2015 at 8:39:22 AM UTC-5, Clyde Balneaves wrote:
Pseudo to working code:

class Application extends GrailsAutoConfiguration implements EnvironmentAware {
    static void main(String[] args) {
        GrailsApp.run(Application)
    }

    @Override
    void setEnvironment(Environment environment) {
        //Set up Configuration directory
        def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken"

        println ""
        println "Loading configuration from ${krakenHome}"
        def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists()
        println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}"
        println "Config file found : " + appConfigured

        if (appConfigured) {
            def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL())
            environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config))
        }
    }
}

On Sunday, March 8, 2015 at 5:30:52 PM UTC-5, Benoit Hediard wrote:
Hi,

In the new Grails 3 documentation, there is no "Externalized configuration" info.
I tried to create an application.groovy and use grails.config.locations without success ;).

Is grails.config.locations not supported anymore?
What would be the equivalent?

Thanks!

Benoit

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/4e509f64-c2a9-4e4c-9230-e39228584809%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

Michael Jess
Any idea on how to implement this as a plugin? I think this would be really useful to the community and I'd even consider maintaining it; the thing is just that even doWithSpring() appears to be run after the configuration has been loaded into the grailsApplication, and therefore changes are not visible.

Is there a lifecycle method for plugins where I could do this? This should happen before the app bootstrap files are executed.

Thanks,
Michael

Am Donnerstag, 21. Mai 2015 12:29:09 UTC+2 schrieb Peyman P:
here a yml version. it works for me:

class Application extends GrailsAutoConfiguration implements EnvironmentAware {
static void main(String[] args) {
GrailsApp.run(Application)
}

@Override
void setEnvironment(Environment environment) {
String configPath = System.properties["appname.config.location"]
Resource resourceConfig = new FileSystemResource(configPath);
YamlPropertiesFactoryBean ypfb = new YamlPropertiesFactoryBean();
ypfb.setResources(resourceConfig);
ypfb.afterPropertiesSet();
Properties properties = ypfb.getObject();
environment.propertySources.addFirst(new PropertiesPropertySource("appname.config.location", properties))
}
}

build.gradle

bootRun {
jvmArgs = ['-Dappname.config.location=/path/to/config.yml']
}



Am Montag, 6. April 2015 19:15:38 UTC+2 schrieb Michael Baehr:
Yeah, environment specific properties is what I'm after. I'm also converting a production application to Grails 3, and I'm not sure if there are customers out there who have environment blocks in their configs. Guess I will have to find out the hard way ... ;)

Thanks for your support, your code was already very helpful!

On Monday, April 6, 2015 at 8:15:13 AM UTC-5, Clyde Balneaves wrote:
Of course if you meant the external config has environment specific properties, then I have no idea!  I've been loading different files based on the logic, or getting Puppet to modify the file based on the environment.

On Thursday, April 2, 2015 at 7:10:27 PM UTC-5, Michael Baehr wrote:
Thanks Clyde, I was running into the same problem, and your code works.

It seems though that the environment{} logic is not supported - I don't see any configuration parameters that are defined inside the environment block. Do you have any idea how this can be enabled?

Thanks

Michael

On Friday, March 27, 2015 at 8:39:22 AM UTC-5, Clyde Balneaves wrote:
Pseudo to working code:

class Application extends GrailsAutoConfiguration implements EnvironmentAware {
    static void main(String[] args) {
        GrailsApp.run(Application)
    }

    @Override
    void setEnvironment(Environment environment) {
        //Set up Configuration directory
        def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken"

        println ""
        println "Loading configuration from ${krakenHome}"
        def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists()
        println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}"
        println "Config file found : " + appConfigured

        if (appConfigured) {
            def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL())
            environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config))
        }
    }
}

On Sunday, March 8, 2015 at 5:30:52 PM UTC-5, Benoit Hediard wrote:
Hi,

In the new Grails 3 documentation, there is no "Externalized configuration" info.
I tried to create an application.groovy and use grails.config.locations without success ;).

Is grails.config.locations not supported anymore?
What would be the equivalent?

Thanks!

Benoit

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/0725361a-a763-4a85-9616-01c7546c54fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

Sami Mäkelä
In reply to this post by Benoit HEDIARD
I did a quick hack to support grails.config.locations

import org.springframework.core.env.Environment
import grails.boot.config.GrailsAutoConfiguration
import org.springframework.core.env.MapPropertySource

class ApplicationConfigurationLoader {

private ApplicationConfigurationLoader() {}

public static load(GrailsAutoConfiguration application, Environment environment) {
if (application && environment) {
DefaultResourceLocator resourceLocator = new DefaultResourceLocator()
def applicationGroovy = application.getClass().classLoader.getResource('application.groovy')
if (applicationGroovy) {
def applicationConfiguration = new ConfigSlurper(grails.util.Environment.current.name).parse(applicationGroovy)
for (String configLocation in applicationConfiguration.grails.config.locations) {
def configurationResource = resourceLocator.findResourceForURI(configLocation)
if (configurationResource) {
def config = new ConfigSlurper(grails.util.Environment.current.name).parse(configurationResource.getURL())
environment.propertySources.addFirst(new MapPropertySource(configLocation, config))
}
}
}
}
}
}

@Override
void setEnvironment(Environment environment) {
ApplicationConfigurationLoader.load(this, environment)
}

On Monday, 9 March 2015 00:30:52 UTC+2, Benoit Hediard wrote:
Hi,

In the new Grails 3 documentation, there is no "Externalized configuration" info.
I tried to create an application.groovy and use grails.config.locations without success ;).

Is grails.config.locations not supported anymore?
What would be the equivalent?

Thanks!

Benoit

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/de4b6d6f-215b-4335-8588-e78a8bdae6aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 3 - External config

tseveen
This post has NOT been accepted by the mailing list yet.
In reply to this post by Benoit HEDIARD
    @Override
    void setEnvironment(Environment environment) {
        load(this, environment)
    }

    static load(GrailsAutoConfiguration application, Environment environment) {
        if (application && environment) {
            DefaultResourceLocator resourceLocator = new DefaultResourceLocator()
            def applicationGroovy = application.getClass().classLoader.getResource('application.groovy')
            if (applicationGroovy) {
                def applicationConfiguration = new ConfigSlurper(grails.util.Environment.current.name).parse(applicationGroovy)
                for (String configLocation in applicationConfiguration.grails.config.locations) {
                    def configurationResource = resourceLocator.findResourceForURI(configLocation)
                    if (configurationResource) {
                        String fileName = configurationResource.getFile().getName()
                        String ext = fileName.lastIndexOf('.').with { it != -1 ? fileName.substring(it + 1) : '' }
                        MapPropertySource source
                        switch (ext.toLowerCase()) {
                            case 'groovy':
                                def config = new ConfigSlurper(grails.util.Environment.current.name).parse(IOUtils.toString(configurationResource.getInputStream(), 'UTF-8'))
                                source = new MapPropertySource(configLocation, config)
                                break
                            case 'properties':
                                PropertiesFactoryBean pfb = new PropertiesFactoryBean()
                                pfb.setFileEncoding('UTF-8')
                                pfb.setLocation(configurationResource)
                                pfb.afterPropertiesSet()
                                Properties properties = pfb.getObject()
                                source = new PropertiesPropertySource(configLocation, properties)
                                break
                            case 'yml':
                                YamlPropertiesFactoryBean ypfb = new YamlPropertiesFactoryBean()
                                ypfb.setResources(configurationResource)
                                ypfb.afterPropertiesSet()
                                Properties properties = ypfb.getObject()
                                source = new PropertiesPropertySource(configLocation, properties)
                                break
                            default:
                                continue
                        }
                        (environment as ConfigurableEnvironment).propertySources.addFirst(source)
                    }
                }
            }
        }
    }
Loading...