首先请检查我所遵循的步骤是否正确。
当我通过URl http://com.cust:8080/sampleapp/user/create
创建新用户时,它正在运行,但问题是我没有使用我为域com.cust
配置的数据库,即custdb
而是使用{{1}这是DataSource.groovy中的全局。
在用户表中,将租户ID 与 0 添加为值 2
在控制台上我收到错误sampleappdb
我正在使用多租户插件配置基本示例应用程序。
我已按照以下步骤配置多租户插件。
Exception in Multi-tenant data source provider
javax.naming.NameNotFoundException: Name jdbc:mysql: is not bound in this Context
grails项目sampleapp
create-domain-class com.myapp.User
generate-all com.myapp.User
数据库以使用已安装的插件
MySQL
已执行的命令plugins.multi-tenant-core=1.0.3
plugins.multi-tenant-ehcache=1.0.1
plugins.falcone-util=1.0
grails create-data-source-map
grails create-dns-map
generate-all tenant.DataSourceTenantMap
带有generate-all tenant.DomainTenantMap
@MultiTenant
在config.groovy中添加了租户块
package com.myapp
import grails.plugin.multitenant.core.groovy.compiler.MultiTenant
@MultiTenant
class User {
String firstName;
String lastName;
static constraints = {
}
}
执行sql命令
tenant {
mode = "singleTenant"
datasourceResolver.type = "db"
resolver.request.dns.type = "config"
resolver.type = "request"
domainTenantMap {
localhost = 1
com.cust = 2
}
}
DataSource.groovy中
INSERT INTO data_source_tenant_map ( VERSION, data_source, mapped_tenant_id) VALUES (0 , "jdbc:mysql://localhost:3306/cust1db?user=user&password=pwd" , 1)
INSERT INTO data_source_tenant_map ( VERSION, data_source, mapped_tenant_id) VALUES (0 , "jdbc:mysql://localhost:3306/custdb?user=user&password=pwd" , 2);
INSERT INTO domain_tenant_map ( VERSION, domain_name, mapped_tenant_id, NAME) VALUES (0 , 'localhost', 1,'Sample Localhost');
INSERT INTO domain_tenant_map ( VERSION, domain_name, mapped_tenant_id, NAME) VALUES (0 , 'com.cust', 2,'127.0.0.1');
使用 grails 1.3.7 版本。 请帮助坚持过去1周。 谢谢。