我正在使用Grails中的Angular项目探索GORM中的动态多租户。目前,我在我的application.yml
中有以下内容grails:
gorm:
multiTenancy:
mode: DATABASE
tenantResolverClass: org.grails.datastore.mapping.multitenancy.web.SubDomainTenantResolver
connectionSourcesClass: org.grails.datastore.mapping.mongo.connections.MongoConnectionSources
connectionsCollection: "myconnections"
dataSource:
dbCreate: create-drop
url: 'mongodb://root:root@localhost:27017?ssl=false&authSource=admin'
这是我的application.yml
grails:
gorm:
multiTenancy:
mode: DATABASE
tenantResolverClass: org.grails.datastore.mapping.multitenancy.web.SubDomainTenantResolver
connectionSourcesClass: org.grails.datastore.mapping.mongo.connections.MongoConnectionSources
connectionsCollection: "myconnections"
dataSource:
dbCreate: create-drop
url: 'mongodb://root:root@localhost:27017?ssl=false&authSource=admin'
我在build.groovy中添加了以下内容并删除了org.grails.plugins:hibernate5
compile "org.mongodb:mongodb-driver:3.4.2"
compile 'org.grails.plugins:mongodb:6.1.2'
根据我是否为我的域类实现MultiTenant接口,在尝试这两件事之后发生了以下事情。
1.如果我实现了界面,那么我会收到以下错误
Caused by: java.lang.IllegalStateException: Either class [com.track.User] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.
我错过了什么?
****更新**** 从头开始创建一个新项目后,我收到以下异常
Caused by: org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException: No tenantId found
at org.grails.datastore.mapping.multitenancy.resolvers.NoTenantResolver.resolveTenantIdentifier(NoTenantResolver.groovy:17)
at grails.gorm.multitenancy.Tenants.currentId(Tenants.groovy:73)
at org.grails.datastore.gorm.GormEnhancer.findTenantId(GormEnhancer.groovy:270)
at org.grails.datastore.gorm.GormEnhancer.findStaticApi(GormEnhancer.groovy:296)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.currentGormStaticApi(GormEntity.groovy:1349)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.count(GormEntity.groovy:628)
at grails.rest.RestfulController.countResources(RestfulController.groovy:275)
at grails.rest.RestfulController.index(RestfulController.groovy:62)
at grails.gorm.transactions.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:94)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at grails.gorm.transactions.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:91)
... 14 common frames omitted