Quantcast

Reading configuration in plugin doWithSpring closure?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Reading configuration in plugin doWithSpring closure?

Andrew Todd
I currently have some Spring beans that I only want to be instantiated
if a particular configuration value is set. There are probably a
number of different ways to do this, but currently it's set up like
this:

    def doWithSpring = {
        if (ConfigurationHolder.config.requiredConfigValue) {
            customBean(com.my.customBean) {
            }
    }

I know that ConfigurationHolder is deprecated, and would like to hear
some opinions about other ways to accomplish this configuration.
Thanks.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Reading configuration in plugin doWithSpring closure?

Ian Roberts
On 25/07/2012 18:18, Andrew Todd wrote:

> I currently have some Spring beans that I only want to be instantiated
> if a particular configuration value is set. There are probably a
> number of different ways to do this, but currently it's set up like
> this:
>
>     def doWithSpring = {
>         if (ConfigurationHolder.config.requiredConfigValue) {
>             customBean(com.my.customBean) {
>             }
>     }
>
> I know that ConfigurationHolder is deprecated, and would like to hear
> some opinions about other ways to accomplish this configuration.
> Thanks.

In doWithSpring you have access to the GrailsApplication in the
"application" variable, so

if(application.config.requiredConfigValue)

will do what you're after.

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Reading configuration in plugin doWithSpring closure?

burtbeckwith
In reply to this post by Andrew Todd
The GrailsApplication is available as the 'application' variable, so you should do this:

   def doWithSpring = {
      if (application.config.requiredConfigValue) {
         customBean(com.my.customBean) {
         }
      }
   }

Burt

Andrew Todd wrote
I currently have some Spring beans that I only want to be instantiated
if a particular configuration value is set. There are probably a
number of different ways to do this, but currently it's set up like
this:

    def doWithSpring = {
        if (ConfigurationHolder.config.requiredConfigValue) {
            customBean(com.my.customBean) {
            }
    }

I know that ConfigurationHolder is deprecated, and would like to hear
some opinions about other ways to accomplish this configuration.
Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Reading configuration in plugin doWithSpring closure?

Andrew Todd
Thanks Ian and Burt, I'll give that a shot. It wasn't clear from the
docs that the application object was available in doWithSpring as
well, since it's not passed into the closure.

On Wed, Jul 25, 2012 at 1:22 PM, burtbeckwith <[hidden email]> wrote:

> The GrailsApplication is available as the 'application' variable, so you
> should do this:
>
>    def doWithSpring = {
>       if (application.config.requiredConfigValue) {
>          customBean(com.my.customBean) {
>          }
>       }
>    }
>
> Burt
>
>
> Andrew Todd wrote
>>
>> I currently have some Spring beans that I only want to be instantiated
>> if a particular configuration value is set. There are probably a
>> number of different ways to do this, but currently it's set up like
>> this:
>>
>>     def doWithSpring = {
>>         if (ConfigurationHolder.config.requiredConfigValue) {
>>             customBean(com.my.customBean) {
>>             }
>>     }
>>
>> I know that ConfigurationHolder is deprecated, and would like to hear
>> some opinions about other ways to accomplish this configuration.
>> Thanks.
>>
>
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Reading-configuration-in-plugin-doWithSpring-closure-tp4632225p4632226.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...