First of all, consider my steps that I followed, right or wrong.
When I create a new user using URl http://com.cust:8080/sampleapp/user/create, it works, but the problem is that the database that I am setting up for the domain is not used com.cust, i.e. custdbusing instead sampleappdb, which is global in DataSource.groovy.
And in the user table, the tenant ID is added with 0 as a value instead of 2
And on the console, I get an error Exception in Multi-tenant data source provider
javax.naming.NameNotFoundException: Name jdbc:mysql: is not bound in this Context
I am setting up a basic sample application with a multi-tenant plugin.
I followed the steps to set up a multi-tenant plugin.
- Grails
sampleappproject created - Completed Counts
create-domain-class com.myapp.User - Performed
generate-all com.myapp.User - customized base
MySQLto use installed plugins
plugins.multi-tenant-core=1.0.3
plugins.multi-tenant-ehcache=1.0.1
plugins.falcone-util=1.0
Executed command grails create-data-source-map
- Executed command
grails create-dns-map - Executed command
generate-all tenant.DataSourceTenantMap - Executed command
generate-all tenant.DomainTenantMap User annotated domain class with @MultiTenant
package com.myapp
import grails.plugin.multitenant.core.groovy.compiler.MultiTenant
@MultiTenant
class User {
String firstName;
String lastName;
static constraints = {
}
}
Added tenant block in config.groovy
tenant {
mode = "singleTenant"
datasourceResolver.type = "db"
resolver.request.dns.type = "config"
resolver.type = "request"
domainTenantMap {
localhost = 1
com.cust = 2
}
}
Sql command is running
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');
DataSource.groovy
development {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost/sampleappdb?autoreconnect=true"
}
}
Using grails version 1.3.7 . Please help get stuck from last week. Thanks.
user4408375
source
share