本文介绍了找不到com.google.cloud.bigtable.hbase1_x.BigtableConnection的适当构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个简单的类来创建表,并使用HBase和Google App Engine添加一些列.我已经在Google Cloud平台中创建了一个项目和一个实例.我克隆了此存储库: https://github.com/GoogleCloudPlatform/cloud-bigtable-examples/blob/master/java/hello-world/src/main/java/com/example/cloud /bigtable/helloworld/HelloWorld.java 在我的实例中创建表就像是一种魅力.但是,当我尝试使用相同的配置创建一个新的Maven项目时,它不起作用,我什么也无法创建.我遇到了这个问题:

I tried to create a simple class to create a table and add some columns with HBase and Google app engine. I have already created a project and an instance in Google Cloud platform.I cloned this repository : https://github.com/GoogleCloudPlatform/cloud-bigtable-examples/blob/master/java/hello-world/src/main/java/com/example/cloud/bigtable/helloworld/HelloWorld.javaIt works like a charm to create a table in my instance. But when I'm trying to create a new maven project with the same config, it doesn't work, I can't create anything.I got this issue :

InvocationTargetException: Could not find an appropriate constructor for com.google.cloud.bigtable.hbase1_x.BigtableConnection: com.google.common.util.concurrent.MoreExecutors.platformThreadFactory()Ljava/util/concurrent/ThreadFactory;

这是我的AudioBridgeData.java文件:

here is my AudioBridgeData.java file :

package com.xxx.xxx;


import com.google.cloud.bigtable.hbase.BigtableConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

/**
 * A minimal application that connects to Cloud Bigtable using the native HBase API
 * and performs some basic operations.
 */
public class AudioBridgeData {

  private static final byte[] TABLE_NAME = Bytes.toBytes("audio-bridge");
  private static final byte[] COLUMN_FAMILY_NAME = Bytes.toBytes("phone-number");
  private static final byte[] COLUMN_NAME = Bytes.toBytes("number");
  private static final String[] NUMBERS =
      { "+33697584976", "+19553560976", "+4879665676" };


  /**
   * Connects to Cloud Bigtable, runs some basic operations and prints the results.
   */
  private static void doAudioBridge(String projectId, String instanceId) {

    try (Connection connection = BigtableConfiguration.connect(projectId, instanceId)) {
      Admin admin = connection.getAdmin();
      HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(TABLE_NAME));
      descriptor.addFamily(new HColumnDescriptor(COLUMN_FAMILY_NAME));

      print("Create table " + descriptor.getNameAsString());
      admin.createTable(descriptor);
      Table table = connection.getTable(TableName.valueOf(TABLE_NAME));
      print("Write some numbers to the table");
      for (int i = 0; i < NUMBERS.length; i++) {
        Put put = new Put(Bytes.toBytes(i));
        put.addColumn(COLUMN_FAMILY_NAME, COLUMN_NAME, Bytes.toBytes(NUMBERS[i]));
        table.put(put);
      }
      int rowKey = 0;
      Result getResult = table.get(new Get(Bytes.toBytes(rowKey)));
      String number = Bytes.toString(getResult.getValue(COLUMN_FAMILY_NAME, COLUMN_NAME));
      System.out.println("Get a single number by row key");
      System.out.printf("\t%s = %s\n", rowKey, number);
      Scan scan = new Scan();

      print("Scan for all numbers:");
      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));
      }

    } catch (IOException e) {
      System.err.println("Exception while running HelloWorld: " + e.getMessage());
      e.printStackTrace();
      System.exit(1);
    }

    System.exit(0);
  }

  private static void print(String msg) {
    System.out.println("Number: " + msg);
  }

  public static void main(String[] args) {
    String projectId = requiredProperty("bigtable.projectID");
    String instanceId = requiredProperty("bigtable.instanceID");

    doAudioBridge(projectId, instanceId);
  }

  private static String requiredProperty(String prop) {
    String value = System.getProperty(prop);
    if (value == null) {
      throw new IllegalArgumentException("Missing required system property: " + prop);
    }
    return value;
  }

}

这是我的pom.xml文件:

Here is my pom.xml file :

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xxx</groupId>
    <artifactId>xxx</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <url>http://maven.apache.org</url>

    <name>xxx</name>

    <properties>
        <bigtable.version>1.0.0-pre1</bigtable.version>
        <hbase.version>1.1.5</hbase.version>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
    </properties>

    <repositories>
    <repository>
        <id>snapshots-repo</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <releases><enabled>false</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
    </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.google.cloud.bigtable</groupId>
            <artifactId>bigtable-hbase-1.x</artifactId>
            <version>${bigtable.version}</version>
        </dependency>

        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-tcnative-boringssl-static</artifactId>
            <version>1.1.33.Fork26</version>
        </dependency>

        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-client</artifactId>
            <version>0.98.11-hadoop2</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.5.0</version>
                <configuration>
                    <mainClass>com.xxx.xxx.AudioBridgeData</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

我尝试运行此命令:

mvn exec:java -Dbigtable.projectID=xxx -Dbigtable.instanceID=quickstart-instance

非常感谢您的帮助! :)

Thanks a lot for your help ! :)

推荐答案

我有相同的错误消息,很奇怪,它是由缺少应用程序凭据引起的.如果是相同的问题,则应设置以下环境变量:

I had the same error message, weirdly it was caused by missing application credentials. If its the same issue you should set this environment variable:

GOOGLE_APPLICATION_CREDENTIALS

GOOGLE_APPLICATION_CREDENTIALS

应将其设置为创建服务帐户密钥后您(可能已)下载的客户端凭据文件的位置.这是一个很好的页面:

It should be set to the location of the client credentials file you (might have) downloaded after creating a service account key. This is a good page:

https://developers.google.com/identity/protocols/application -default-credentials

这篇关于找不到com.google.cloud.bigtable.hbase1_x.BigtableConnection的适当构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 01:20