Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多租户数据源提供程序javax.naming.NameNotFoundException:Name jdbc:mysql:中的Grails/java:Exception未在此上下文中绑定_Java_Grails_Plugins_Grails Plugin_Multi Tenant - Fatal编程技术网

多租户数据源提供程序javax.naming.NameNotFoundException:Name jdbc:mysql:中的Grails/java:Exception未在此上下文中绑定

多租户数据源提供程序javax.naming.NameNotFoundException:Name jdbc:mysql:中的Grails/java:Exception未在此上下文中绑定,java,grails,plugins,grails-plugin,multi-tenant,Java,Grails,Plugins,Grails Plugin,Multi Tenant,首先,请检查我遵循的步骤是否正确。 当我通过URl创建新用户时http://com.cust:8080/sampleapp/user/create它正在工作,但问题是没有使用我为域com.cust配置的数据库,即custdb,而是使用DataSource.groovy中全局的sampleappdb 在user表中,添加租户id,将0改为2 在控制台上,我在多租户数据源提供程序中收到错误异常 javax.naming.NameNotFoundException:Name jdbc:mysql:未在

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

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

user表中,添加租户id,将0改为2

在控制台上,我在多租户数据源提供程序中收到错误
异常
javax.naming.NameNotFoundException:Name jdbc:mysql:未在此上下文中绑定

我正在配置一个带有多租户插件的基本示例应用程序

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

  • 创建了
    sampleapp
    grails项目
  • 已执行grails
    创建域类com.myapp.User
  • 已执行
    生成所有com.myapp.User
  • 已配置要使用的
    MySQL
    数据库
  • 已安装的插件

    plugins.multi-tenant-core=1.0.3
    plugins.multi-tenant-ehcache=1.0.1
    plugins.falcone-util=1.0
    
  • 执行命令
    grails创建数据源映射

  • 已执行命令
    grails创建dns映射
  • 已执行命令
    生成所有租户.DataSourceTenantMap
  • 已执行命令
    生成所有租户.domaintnantmap
  • 带有
    @MultiTenant

    package com.myapp
    import grails.plugin.multitenant.core.groovy.compiler.MultiTenant
    
    @MultiTenant
    class User {
        String firstName;
        String lastName;
        static constraints = {
        }
    }
    
  • 在config.groovy中添加了租户块

    tenant {
            mode = "singleTenant"
            datasourceResolver.type = "db"
            resolver.request.dns.type = "config"
            resolver.type = "request"
            domainTenantMap {
                localhost = 1
                com.cust = 2
            }
    }
    
  • 在sql命令下执行

     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"
            }
        }
    
    使用Grails1.3.7版本。 请从上一周开始帮助我谢谢。