我可以在grails项目中一起使用mongodb插件和gmongo吗?

时间:2014-05-13 16:04:42

标签: mongodb grails gmongo

最近,我正在使用grails项目并打算使用mongodb作为我们的nosql数据库,除了mysql。

我添加了mongodb插件,使用域进行测试并且运行良好(显示/编辑/保存...):

compile ':mongodb:3.0.1'

并尝试使用gmongo插件的另一种方法,这在我想使用mongodb低级API(或使用mapReduce)的情况下非常有用

runtime "org.mongodb:mongo-java-driver:2.11.3"
compile "org.mongodb:mongo-java-driver:2.11.3"
runtime "com.gmongo:gmongo:1.3"

尝试使用简单查询find()进行测试,它也可以正常运行

现在我想结合2方法,这里是错误:

| Error 2014-05-13 17:52:07,197 [localhost-startStop-1] ERROR plugins.DefaultGrailsPluginManager  - Error configuring dynamic methods for plugin [mongodb:3.0.1]: com/mongodb/AggregationOptions
Message: com/mongodb/AggregationOptions
    Line | Method
->> 2531 | privateGetDeclaredMethods in java.lang.Class
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1855 | getDeclaredMethods        in     ''
|     46 | getLocked . . . . . . . . in org.codehaus.groovy.util.LazyReference
|     33 | get                       in     ''
|     98 | createGormStaticApi . . . in org.grails.datastore.gorm.mongo.plugin.support.MongoMethodsConfigurer
|     65 | configure                 in org.grails.datastore.gorm.plugin.support.DynamicMethodsConfigurer
|     49 | configure . . . . . . . . in org.grails.datastore.gorm.mongo.plugin.support.MongoMethodsConfigurer
|     76 | doCall                    in MongodbGrailsPlugin$_closure2
|    262 | run . . . . . . . . . . . in java.util.concurrent.FutureTask
|   1145 | runWorker                 in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                       in java.lang.Thread
Caused by ClassNotFoundException: com.mongodb.AggregationOptions
->>  366 | run                       in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    355 | run                       in     ''
|    354 | findClass . . . . . . . . in java.net.URLClassLoader
|    425 | loadClass                 in java.lang.ClassLoader
|   2531 | privateGetDeclaredMethods in java.lang.Class
|   1855 | getDeclaredMethods        in     ''
|     46 | getLocked . . . . . . . . in org.codehaus.groovy.util.LazyReference
|     33 | get                       in     ''
|     98 | createGormStaticApi . . . in org.grails.datastore.gorm.mongo.plugin.support.MongoMethodsConfigurer
|     65 | configure                 in org.grails.datastore.gorm.plugin.support.DynamicMethodsConfigurer
|     49 | configure . . . . . . . . in org.grails.datastore.gorm.mongo.plugin.support.MongoMethodsConfigurer
|     76 | doCall                    in MongodbGrailsPlugin$_closure2
|    262 | run . . . . . . . . . . . in java.util.concurrent.FutureTask
|   1145 | runWorker                 in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                       in java.lang.Thread

我实际上不知道如何修复它!

1 个答案:

答案 0 :(得分:3)

Mongodb插件是GMongo的一个包装器,具有GORM功能。您绝对可以直接从插件中使用GMongo或更低级别的API,而不是明确添加这些依赖项。

查看包含它们的build.gradle。最有可能的错误是由于同时使用它们时的冲突依赖性。