我有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 –