resources.groovy, types for external properties

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

resources.groovy, types for external properties

rlovtangen
Any reason this bean:

        mongo(GMongo, '${mongodb.host}', '${mongodb.port}') {
        }

selects a different constructor than this bean? :

        mongo(GMongo, '${mongodb.host}', 27017) {
        }

The first bean selects the constructor GMongo(ServerAddress left, ServerAddress right), while the second bean selects the constructor GMongo(String host, Integer port) as expected.


Relevant part of Config.groovy:

mongodb {
        dbname = "rapp"
        port = 27017
        host = "127.0.0.1"
}


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: resources.groovy, types for external properties

Wolfgang Schell
Ronny Løvtangen wrote
Any reason this bean:

        mongo(GMongo, '${mongodb.host}', '${mongodb.port}') {
        }

selects a different constructor than this bean? :

        mongo(GMongo, '${mongodb.host}', 27017) {
        }

The first bean selects the constructor GMongo(ServerAddress left, ServerAddress right), while the second bean selects the constructor GMongo(String host, Integer port) as expected.
The second variant is a straight match to the second constructor, so no surprise there. Why it selects the first constructor for String/String args, I can't tell, but what you probably want is something like this:

        mongo(GMongo, application.config.mongodb.host, application.config.mongodb.port.toInteger()) {
        }

HTH,

Wolfgang

Reply | Threaded
Open this post in threaded view
|

Re: resources.groovy, types for external properties

rlovtangen
Thanks Wolfgang!

Works like a charm, didn't even need the toInteger() part, as Config.groovy is not limited to Strings.
Didn't know I had 'application' available in resources.groovy.

Ronny

On Apr 13, 2011, at 9:52 PM, Wolfgang Schell wrote:

>
> Ronny Løvtangen wrote:
>>
>> Any reason this bean:
>>
>> mongo(GMongo, '${mongodb.host}', '${mongodb.port}') {
>> }
>>
>> selects a different constructor than this bean? :
>>
>> mongo(GMongo, '${mongodb.host}', 27017) {
>> }
>>
>> The first bean selects the constructor GMongo(ServerAddress left,
>> ServerAddress right), while the second bean selects the constructor
>> GMongo(String host, Integer port) as expected.
>>
>
> The second variant is a straight match to the second constructor, so no
> surprise there. Why it selects the first constructor for String/String args,
> I can't tell, but what you probably want is something like this:
>
> mongo(GMongo, application.config.mongodb.host,
> application.config.mongodb.port.toInteger()) {
> }
>
> HTH,
>
> Wolfgang
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/resources-groovy-types-for-external-properties-tp3447554p3448077.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