我有2個我的難題:導入域類從格姆-獨立模塊到Grails的
1)命名core-module
與獨立GORM無Grails項目:
dependencies {
compile 'org.grails:grails-datastore-gorm-mongodb:6.0.4.RELEASE'
compile 'org.grails:grails-validation:3.2.3'
}
和域類,如:
import grails.gorm.annotation.Entity
@Entity
class Module {
String id
String tags
}
的GORM-ING由
Map config = new Yaml().load this.class.getResource('/application.yml').text
new MongoDatastore(config, Module, UserAccount)
初始化
和域類正如他們在Grails應用程序中那樣工作。
2)Grails 3.2.3
應用:
dependencies {
// default grails dependencies
compile project(':core-module')
compile 'org.grails.plugins:mongodb:6.0.4'
compile 'org.grails.plugins:spring-security-core:3.1.1'
// etc
}
的格姆被初始化:
def config = config.grails.mongodb
log.info "using $config"
new MongoDatastore(config, Module, UserAccount)
,並打印出該記錄到日誌文件:
g.app。 init.com.mozaiq.Application - 使用[host:localhost,port:27017,databaseName:theDB,用戶名:theUN,pooled:true,mongoOptions:[connectionsPerHost:100 ,autoConnectRetry:真,connectTimeout:3000]
的問題是,該財產grailsApplication.domainClasses
是空的,即使Module.collection
不爲空,則Module.count()
回報0
儘管收集是不是空的。
同樣在我的mongo客戶端中,我發現在應用程序啓動時創建了一個新的數據庫test
,它由一個空集合創建,並由我的一個域類命名。如果我插入一些文檔,則.count()
返回0
,並且CRUD列表保持空白。
是否可以在非Grails應用程序中掃描某些包中的所有域類? – injecteer
另外我注意到,控制器中的'respond'方法返回一個空的域實例,就像'def show(Module module){respond module}'顯示一個空頁面 – injecteer
我們正在爲GORM 6.1添加掃描,同時你可以使用與此類似的代碼編寫自己的掃描https://github.com/grails/gorm-hibernate5/blob/6.0.x/grails-plugin/src/main/groovy/grails/test/hibernate/HibernateSpec.groovy# L48 –