我一直在尝试将mongodb与grails一起使用。为此,在BuildConfig.groovy的插件部分中添加以下代码

compile ":mongodb:3.0.3"  

然后,将DataSource.groovy更改为以下内容:
          grails { 
            mongo { 
              host = "localhost" 
              port = 27107 
              username = "user" 
              password="secretpassword" 
              databaseName = "physicians" 
            } 
          } 

但这会导致编译错误,如下所示:
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 

您能告诉我如何解决该错误吗?顺便说一句,我一直关注的教程可以在下面的链接中找到:
http://blog.mongodb.org/post/18510469058/grails-in-the-land-of-mongodb

请您参考如下方法:

您的服务器无法访问,您可以在异常跟踪中清楚地看到:

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


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!