How do I externalize mongodb config?

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

How do I externalize mongodb config?

mschneider01
This post was updated on .
Hi list,

can anybody help me with the externalization of the mongodb config?
I've read the documentation of the mongodb plugin but didn't find anything
regarding this topic. Also, I've read the following post but couldn't get
it to work.

http://grails.1312388.n4.nabble.com/resources-groovy-types-for-external-properties-td3447554.html

I'm using Grails 2.0.4 + MongoDB-Plugin 1.0.0.GA

Can give me anybody a clue?

Thank you in advance.
-markus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to externalize db config...

Arash Sharif

Look into jndi

On Jul 7, 2012 9:10 AM, "mschneider01" <[hidden email]> wrote:
Hi list,

can anybody help me with the externalization of the mongodb config?
I've read the documentation of the mongodb plugin but didn't find anything
regarding this topic. Also, I've read the following post but couldn't get
it to work.

http://grails.1312388.n4.nabble.com/resources-groovy-types-for-external-properties-td3447554.html

I'm using Grails 2.0.4 + MongoDB-Plugin 1.0.0.GA

Can give me anybody a clue?

-markus

--
View this message in context: http://grails.1312388.n4.nabble.com/How-to-externalize-db-config-tp4631242.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


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

Re: How to externalize db config...

mschneider01
Hi Arash,

thank you very much for your help. But can you give me some more details how to do that?

-markus

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

Re: How to externalize db config...

mschneider01
Basically I'd expect that I can externalize the mongodb config the same way I do it with
any other data source e.g. mysql

Externalized MySQL Config
===

DBConfig.properites
---
dataSource.pooled=true
dataSource.url=jdbc:mysql://localhost/testDB
dataSource.driverClassName=com.mysql.jdbc.Driver
dataSource.dbCreate=create-drop
dataSource.username=root
dataSource.password=Changeit123
dataSource.minEvictableIdleTimeMillis=1800000
dataSource.timeBetweenEvictionRunsMillis=1800000
dataSource.numTestsPerEvictionRun=3
dataSource.testOnBorrow=true
dataSource.testWhileIdle=true
dataSource.testOnReturn=true
dataSource.validationQuery="SELECT 1"


Config.groovy
---
grails.config.locations = ["classpath:testApp/core/DBConfig.properties"]


Externalized MongoDB Config - Approach
===

MongoDBConfig.properties
---
grails.mongo.host = "localhost"
grails.mongo.port = 27017
grails.mongo.username = "admin"
grails.mongo.password = "Changeit123"
grails.mongo.databaseName = "testDB"

Config.groovy
===
grails.config.locations = ["classpath:testApp/core/MongoDBConfig.properties"]

Then I get the following error message:

2012-07-07 21:25:45,305 [pool-5-thread-1] ERROR context.GrailsContextLoader  - Error executing bootstraps: Error creating bean with name 'mongoDatastore': Cannot resolve reference to bean 'mongoBean' while setting bean property 'mongo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo': Invocation of init method failed; nested exception is java.net.UnknownHostException: "localhost"
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': Cannot resolve reference to bean 'mongoBean' while setting bean property 'mongo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo': Invocation of init method failed; nested exception is java.net.UnknownHostException: "localhost"
        at org.grails.datastore.gorm.plugin.support.PersistenceContextInterceptorAggregator.postProcessBeanFactory(PersistenceContextInterceptorAggregator.groovy:100)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo': Invocation of init method failed; nested exception is java.net.UnknownHostException: "localhost"
        ... 6 more
Caused by: java.net.UnknownHostException: "localhost"
        at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
        at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1202)
        at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
        at java.net.InetAddress.getAllByName(InetAddress.java:1083)
        at java.net.InetAddress.getAllByName(InetAddress.java:1019)
        at com.mongodb.ServerAddress._getAddress(ServerAddress.java:223)
        at com.mongodb.ServerAddress.<init>(ServerAddress.java:75)
        at org.grails.datastore.gorm.mongo.bean.factory.GMongoFactoryBean.afterPropertiesSet(GMongoFactoryBean.java:106)
        ... 6 more

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

Re: How to externalize db config...

bksaville
Your method is correct, but localhost is a strange one - use 127.0.0.1 instead and it should work just as you have it with the external properties file.  Typically mongo is setup to bind only to the IP address and not to localhost if I remember right.
-Brian

On Sat, Jul 7, 2012 at 1:30 PM, mschneider-1 <[hidden email]> wrote:
Basically I'd expect that I can externalize the mongodb config the same way I
do it with
any other data source e.g. mysql

Externalized MySQL Config
===

DBConfig.properites
---
dataSource.pooled=true
dataSource.url=jdbc:mysql://localhost/testDB
dataSource.driverClassName=com.mysql.jdbc.Driver
dataSource.dbCreate=create-drop
dataSource.username=root
dataSource.password=Changeit123
dataSource.minEvictableIdleTimeMillis=1800000
dataSource.timeBetweenEvictionRunsMillis=1800000
dataSource.numTestsPerEvictionRun=3
dataSource.testOnBorrow=true
dataSource.testWhileIdle=true
dataSource.testOnReturn=true
dataSource.validationQuery="SELECT 1"


Config.groovy
---
grails.config.locations = ["classpath:testApp/core/DBConfig.properties"]


Externalized MongoDB Config - Approach
===

MongoDBConfig.properties
---
grails.mongo.host = "localhost"
grails.mongo.port = 27017
grails.mongo.username = "admin"
grails.mongo.password = "Changeit123"
grails.mongo.databaseName = "testDB"

Config.groovy
===
grails.config.locations =
["classpath:testApp/core/MongoDBConfig.properties"]

Then I get the following error message:

2012-07-07 21:25:45,305 [pool-5-thread-1] ERROR context.GrailsContextLoader
- Error executing bootstraps: Error creating bean with name
'mongoDatastore': Cannot resolve reference to bean 'mongoBean' while setting
bean property 'mongo'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'mongo': Invocation of init method failed; nested exception is
java.net.UnknownHostException: "localhost"
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'mongoDatastore': Cannot resolve reference to bean 'mongoBean'
while setting bean property 'mongo'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'mongo': Invocation of init method failed; nested exception is
java.net.UnknownHostException: "localhost"
        at
org.grails.datastore.gorm.plugin.support.PersistenceContextInterceptorAggregator.postProcessBeanFactory(PersistenceContextInterceptorAggregator.groovy:100)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'mongo': Invocation of init method failed; nested
exception is java.net.UnknownHostException: "localhost"
        ... 6 more
Caused by: java.net.UnknownHostException: "localhost"
        at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
        at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1202)
        at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
        at java.net.InetAddress.getAllByName(InetAddress.java:1083)
        at java.net.InetAddress.getAllByName(InetAddress.java:1019)
        at com.mongodb.ServerAddress._getAddress(ServerAddress.java:223)
        at com.mongodb.ServerAddress.<init>(ServerAddress.java:75)
        at
org.grails.datastore.gorm.mongo.bean.factory.GMongoFactoryBean.afterPropertiesSet(GMongoFactoryBean.java:106)
        ... 6 more

-markus

--
View this message in context: http://grails.1312388.n4.nabble.com/How-do-I-externalize-mongodb-config-tp4631242p4631248.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



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

Re: How to externalize db config...

mschneider01
Hi Brian,

thank you very much for your fast reply. Problem is now solved. You are right - one problem
was the localhost and the others were the quotes.

OLD - not working version/with localhost + quotes
---
grails.mongo.host = "localhost"
grails.mongo.port = 27017
grails.mongo.username = "admin"
grails.mongo.password = "Changeit123"
grails.mongo.databaseName = "testDB"

NEW - working version/with ip-address + no quotes
---
grails.mongo.host = 127.0.0.1
grails.mongo.port = 27017
grails.mongo.username = admin
grails.mongo.password = Changeit123
grails.mongo.databaseName = testDB

Thanks again for the help.

-markus

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

Re: How to externalize db config...

vinaykr91
Hi mschneider01 ,

May I know how you were able to achieve that? Exactly what were the steps you followed ?

Where did you place the MongoDBConfig.properties file ? Inside project folder or somewhere else.
Thanks
Loading...