2

I have been trying to use mongodb with grails. To do that add the following code in the plugin part in BuildConfig.groovy

compile ":mongodb:3.0.3" 

Then I have changed DataSource.groovy into the follwings:

          grails {
            mongo {
              host = "localhost"
              port = 27107
              username = "user"
              password="secretpassword"
              databaseName = "physicians"
            }
          }

But it causes compilation error as followings:

Error |
2015-07-14 14:29:53,412 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'mongoTransactionManager' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is 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 com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'mongoTransactionManager' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is 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 com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms
    Line | Method
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    724 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'mongoTransactionManager' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is 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 com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    724 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is 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 com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    724 | run . . . in java.lang.Thread
Caused by 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 com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    724 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'mongo': Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    724 | run . . . in java.lang.Thread
Caused by MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms
->>   87 | getServer in com.mongodb.BaseCluster
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    654 | getServer in com.mongodb.DBTCPConnector
|     39 | access$300 in     ''
|    503 | getConnection in com.mongodb.DBTCPConnector$MyPort
|    451 | get . . . in     ''
|    624 | authenticate in com.mongodb.DBTCPConnector
|    195 | doAuthenticate in com.mongodb.DBApiLayer
|    765 | authenticateCommandHelper in com.mongodb.DB
|    721 | authenticate in     ''
|    149 | afterPropertiesSet in org.grails.datastore.gorm.mongo.bean.factory.GMongoFactoryBean
|    334 | innerRun  in java.util.concurrent.FutureTask$Sync
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    724 | run . . . in java.lang.Thread
Error |
Forked Grails VM exited with error

Can you please tell me how to fix the error. Btw, the tutorial that i have been following can be found in below link : http://blog.mongodb.org/post/18510469058/grails-in-the-land-of-mongodb

2 Answers2

0

your server is not reachable, what you can clearly see in the exception trace:

Caused by MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms

injecteer
  • 20,038
  • 4
  • 45
  • 89
0

So here is what's happening:

First off all you need to confirm if your Mongo service is running either by just entering mongo command (and see if you land to Mongo shell) or by ps -A | grep mongod.

In any case if the MongoDB service is running then you first need to start your service.

sudo service mongod start # For Ubuntu & CentOS
# OR
mongod --config /etc/mognod.conf

(I've given you the example for Ubuntu & CentOS. Read this if you are using different OS.)

Now, after you started service or confirmed that MongoDB server is up & running you need to do run-app.

One thing I saw problematic in your question in the port number i.e. 27107 instead of 27017. I'm not sure if this is by mistake in the question or you have added this to your Grails DataSource.groovy file. By default, MongoDB runs on the port number 27017 (although you can configure it). So this can be your problem.

So change that port number to 27017 and then do grails run-app. This should work.

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121