Grails / java:多租户数据源提供程序中的异常javax.naming.NameNotFoundException:名称jdbc:mysql:未绑定在此Context

时间:2016-02-12 10:52:26

标签: java grails plugins grails-plugin multi-tenant

首先请检查我所遵循的步骤是否正确。

当我通过URl http://com.cust:8080/sampleapp/user/create创建新用户时,它正在运行,但问题是我没有使用我为域com.cust配置的数据库,即custdb而是使用{{1}这是DataSource.groovy中的全局。

用户表中,将租户ID 0 添加为值 2

在控制台上我收到错误sampleappdb

我正在使用多租户插件配置基本示例应用程序。

我已按照以下步骤配置多租户插件。

  1. 创建了Exception in Multi-tenant data source provider javax.naming.NameNotFoundException: Name jdbc:mysql: is not bound in this Context grails项目
  2. 执行grails sampleapp
  3. 已执行create-domain-class com.myapp.User
  4. 配置generate-all com.myapp.User数据库以使用
  5. 已安装的插件

    MySQL
  6. 已执行的命令plugins.multi-tenant-core=1.0.3 plugins.multi-tenant-ehcache=1.0.1 plugins.falcone-util=1.0

  7. 执行命令grails create-data-source-map
  8. 执行命令grails create-dns-map
  9. 执行命令generate-all tenant.DataSourceTenantMap
  10. 带有generate-all tenant.DomainTenantMap

    的带注释用户域类
    @MultiTenant
  11. 在config.groovy中添加了租户块

    package com.myapp
    import grails.plugin.multitenant.core.groovy.compiler.MultiTenant
    
    @MultiTenant
    class User {
        String firstName;
        String lastName;
        static constraints = {
        }
    }
    
  12. 执行sql命令

    tenant {
            mode = "singleTenant"
            datasourceResolver.type = "db"
            resolver.request.dns.type = "config"
            resolver.type = "request"
            domainTenantMap {
                localhost = 1
                com.cust = 2
            }
    }
    
  13. 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周。 谢谢。

0 个答案:

没有答案