Java Bigtable模拟器。找不到合适的构造函数

Java Bigtable模拟器。找不到合适的构造函数,java,gcloud,bigtable,Java,Gcloud,Bigtable,最近,我试图在IntelliJ IDEA工具上开发一些使用Bigtable emulator和java(Spring Boot)的东西 我所做的: Bigtable emulator在我的计算机(MacOs 10.15.6)上运行良好。 “cbt”通常与运行在mac上的Bigtable emulator一起工作 我已经检查过运行Bigtable emulator不需要真正的gcloud凭据。 Configuration conf; Connection connection = null

最近,我试图在IntelliJ IDEA工具上开发一些使用Bigtable emulator和java(Spring Boot)的东西

我所做的:

  • Bigtable emulator在我的计算机(MacOs 10.15.6)上运行良好。

  • “cbt”通常与运行在mac上的Bigtable emulator一起工作

  • 我已经检查过运行Bigtable emulator不需要真正的gcloud凭据。

    Configuration conf;
    Connection connection = null;
    conf = BigtableConfiguration.configure("fake-project", "fake-instance");
    String host = "localhost";
    String port = "8086";
    
  • 我在IEDA上写了一个单元测试,效果很好。 我在如下设置中添加了环境变量:
  • 我的单元测试代码:

    I.连接初始化:

    Configuration conf;
    Connection connection = null;
    conf = BigtableConfiguration.configure("fake-project", "fake-instance");
    
    String host = "localhost";
    String port = "8086";
    
    
    二,。要写入表中的常量数据

    final byte[] TABLE_NAME = Bytes.toBytes("Hello-Bigtable");
    final byte[] COLUMN_FAMILY_NAME = Bytes.toBytes("cf1");
    final byte[] COLUMN_NAME = Bytes.toBytes("greeting");
    
    final String[] GREETINGS = {
            "Hello World!", "Hello Cloud Bigtable!", "Hello!!"
    };
    
    
    三、 连接:(复制到I.Connect init。)

    三、 连接:(已编辑)

    四、 写入和读取数据:

    
    Admin admin = connection.getAdmin();
    Table table = connection.getTable(TableName.valueOf(TABLE_NAME));
    if(!admin.tableExists(TableName.valueOf(TABLE_NAME))){
        HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(TABLE_NAME));
        descriptor.addFamily(new HColumnDescriptor(COLUMN_FAMILY_NAME));
        System.out.print("Create table " + descriptor.getNameAsString());
        admin.createTable(descriptor);
    }
    for (int i = 0; i < GREETINGS.length; i++) {
        String rowKey = "greeting" + i;
    
        Put put = new Put(Bytes.toBytes(rowKey));
        put.addColumn(COLUMN_FAMILY_NAME, COLUMN_NAME, Bytes.toBytes(GREETINGS[i]));
        table.put(put);
    }
    Scan scan = new Scan();
    ResultScanner scanner = table.getScanner(scan);
    for (Result row : scanner) {
        byte[] valueBytes = row.getValue(COLUMN_FAMILY_NAME, COLUMN_NAME);
        System.out.println('\t' + Bytes.toString(valueBytes));
    }
    
    

    问题是在我将此代码添加到我的项目中之后出现的。 当我使用“debug”运行代码时

    我得到了这样的东西 当它尝试连接bigtable时: 似乎无法基于我创建的配置创建新实例

    最后,它向我显示了一个错误,比如

    Could not find an appropriate constructor for com.google.cloud.bigtable.hbase1_x.BigtableConnection
    
    另外,我试着使用运行IntelliJ IDEA的命令。我这样做的原因是因为我在使用单元测试时缺少环境变量。 在我的.zshrc文件中:

    我的CMD工具是带有oh myzsh的iTerm2

    任何事情都是有帮助的


    非常感谢。

    您似乎错过了:
    BigtableConnection(org.apache.hadoop.conf.conf)的构造函数。

    我建议您尝试按照中提到的步骤创建
    连接
    对象


    您似乎错过了:
    BigtableConnection(org.apache.hadoop.conf.conf)的构造函数

    我建议您尝试按照中提到的步骤创建
    连接
    对象


    谢谢你的回答!我发现我的问题中有重复的代码。您提到的步骤我已经在我的代码中完成了@我已经编辑了我的问题,并将重复的代码标记为已删除。可能一些参数没有正确地传递到
    config.set()
    。您能否对
    if
    语句进行注释,并按照上述文档中建议的方式传递参数?谢谢您的回答!我发现我的问题中有重复的代码。您提到的步骤我已经在我的代码中完成了@我已经编辑了我的问题,并将重复的代码标记为已删除。可能一些参数没有正确地传递到
    config.set()
    。您能否对
    if
    语句进行注释,并按照上述文档中建议的方式传递参数?
        Hello World!
        Hello Cloud Bigtable!
        Hello!!
    
    Could not find an appropriate constructor for com.google.cloud.bigtable.hbase1_x.BigtableConnection
    
    private static Connection connection = null;
       
    public static void connect() throws IOException {
        Configuration config = BigtableConfiguration.configure(PROJECT_ID, INSTANCE_ID);
        // Include the following line if you are using app profiles.
        // If you do not include the following line, the connection uses the
        // default app profile.
        config.set(BigtableOptionsFactory.APP_PROFILE_ID_KEY, APP_PROFILE_ID);
        connection = BigtableConfiguration.connect(config);
    }