【问题标题】:Completely lost on getting grails 3.X.X work with mongob完全迷失了让 grails 3.X 与 mongodb 一起工作
【发布时间】:2016-05-23 17:37:54
【问题描述】:

我一直在努力让 grails 3.1.7 连接到本地 mongo db。我已经通过main documentation 实施了各种建议。我通过Alex MArmarnath 浏览了一些关于stackoverflow 的帖子

我的 build.gradle 如下所示:

// ...
compile 'org.grails.plugins:mongodb'
compile "org.mongodb:mongodb-driver:3.0.2"
runtime 'org.springframework.data:spring-data-mongodb:1.8.1.RELEASE'
//compile 'org.mongodb:mongo-java-driver'
//compile("org.grails:gorm-mongodb-spring-boot:5.0.6.RELEASE")

//compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
//compile "org.hibernate:hibernate-ehcache"
// ...

我的 application.yml 看起来像下面的 sn-p:

//...
 environments:
  development:
    dataSource:
      grails:
        mongodb:
          connectionString: "mongodb://localhost:27017/project-db"
#        dbCreate: create-drop
#        url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
test:
    dataSource:
#        dbCreate: update
#        url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
    dataSource:
#        dbCreate: update
#         url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
#        properties:
#            jmxEnabled: true

//...

这是一个示例模型:

class FlowInfo {

    int posIndex
    String tagName
    Boolean isEnabled
    String name
    static mapWith="mongo"
    static constraints = {
        posIndex unique: true
    }


}

看起来我仍在从可能在 BootStrap.groovy 播种的第一次运行时创建的第一个初始内存数据库中提取数据。有没有办法使这项工作。看起来不同的策略适用于不同的人。

感谢您阅读本文。

【问题讨论】:

  • 您是否尝试过在您的域中使用 static mapWith = "mongo" 属性?
  • 抱歉回复晚了。我确实有 mapWith

标签: mongodb grails grails-orm


【解决方案1】:

我在 application.yml 中尝试了以下对我有用的配置:

environments:
    development:
        grails:
            mongodb:
                connectionString: mongodb://localhost:27017/database-name

您可以删除 dataSource 并尝试一次。

【讨论】:

  • 感谢您的建议。我已升级到 3.1.7,并遵循最新文档,注释掉所有数据源内容,但使用 application.groovy 文件。
  • 你能上传例子在github上复现吗?
猜你喜欢
  • 1970-01-01
  • 2015-08-10
  • 1970-01-01
  • 1970-01-01
  • 2013-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-06
相关资源
最近更新 更多