Не удается подключиться к Bigtable из приложения Spring Boot

У меня есть отдельное приложение, которое отлично работает с Bigtable при создании такого соединения:

Connection connection = BigtableConfiguration.connect(PROJECT_ID, INSTANCE_ID)

и используя следующие зависимости:

<dependency>
    <groupId>com.google.apis</groupId>
    <artifactId>google-api-services-storage</artifactId>
    <version>v1-rev78-1.22.0</version>
</dependency>
<dependency>
    <groupId>com.google.apis</groupId>
    <artifactId>google-api-services-pubsub</artifactId>
    <version>v1-rev11-1.22.0</version>
</dependency>
<dependency>
    <groupId>com.google.cloud.bigtable</groupId>
    <artifactId>bigtable-hbase-1.2</artifactId>
    <version>0.9.5</version>
</dependency>
<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-client</artifactId>
    <version>1.2.4</version>
</dependency>
<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-tcnative-boringssl-static</artifactId>
    <version>1.1.33.Fork26</version>
</dependency>

Сейчас я конвертирую его в веб-приложение Spring Boot, поэтому мне пришлось добавить эту зависимость:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>1.4.2.RELEASE</version>
</dependency>

Я больше ничего не менял, просто добавил эти 5 строк, и теперь я получаю эту ошибку:

java.lang.IllegalStateException: Could not find an appropriate constructor for com.google.cloud.bigtable.hbase1_1.BigtableConnection
    at com.google.cloud.bigtable.hbase.BigtableConfiguration.connect(BigtableConfiguration.java:88)
    at com.google.cloud.bigtable.hbase.BigtableConfiguration.connect(BigtableConfiguration.java:72)
    at poc.google.cloud.BigtableTest.testHelloWorld(BigtableTest.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.google.cloud.bigtable.hbase.BigtableConfiguration.connect(BigtableConfiguration.java:85)
    ... 28 more
Caused by: java.lang.IllegalStateException: Neither Jetty ALPN nor OpenSSL via netty-tcnative were properly configured.
    at com.google.cloud.bigtable.grpc.BigtableSession.<init>(BigtableSession.java:258)
    at org.apache.hadoop.hbase.client.AbstractBigtableConnection.<init>(AbstractBigtableConnection.java:137)
    at org.apache.hadoop.hbase.client.AbstractBigtableConnection.<init>(AbstractBigtableConnection.java:104)
    at com.google.cloud.bigtable.hbase1_1.BigtableConnection.<init>(BigtableConnection.java:48)
    ... 33 more

person cahen    schedule 23.01.2017    source источник
comment
Я не думаю, что когда-либо тестировал tcnative Fork26 и мне повезло с Fork19; Я не знаю, в этом ли дело. Я столкнулся с различными путями к классам, связанными с tcnative, возникающими из-за проблем с порядком в средах jetty и tomcat, например: github.com/GoogleCloudPlatform/cloud-bigtable-client/issues/876 и stackoverflow.com/questions/39421958/. Я не мог отладить проблемы   -  person Solomon Duskis    schedule 23.01.2017
comment
Я пробовал 1.1.33.Fork19 безуспешно. На данный момент я знаю, что это как-то связано с транзитивной зависимостью org.apache.tomcat.embed:spring-boot-starter-tomcat, привнесенной spring-boot-starter-web.   -  person cahen    schedule 23.01.2017
comment
«tc» в tcnative означает tomcat. Когда доступны tcnative и tomcat, возникает какой-то конфликт. Одной из возможных альтернатив является использование alpn_boot, хотя gRPC настоятельно не рекомендует этого делать... github.com/grpc/grpc-java/blob/master/   -  person Solomon Duskis    schedule 23.01.2017
comment
Я нашел простой обходной путь, как описано в моем ответе, на случай, если он поможет вам в будущих разработках клиентской библиотеки Bigtable java. Большое спасибо   -  person cahen    schedule 23.01.2017


Ответы (1)


Библиотеки, используемые для подключения к Bigtable, похоже, имеют какой-то конфликт с библиотеками Tomcat, используемыми Spring Boot по умолчанию.

В качестве обходного пути используйте Jetty вместо Tomcat.

Кроме того, после этого перехода пропал com.google.protobuf:protobuf-java, так что не забудьте добавить и его.

Вот как вы заменяете Tomcat для Jetty в Spring Boot:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<!-- Excluding spring-boot-starter-tomcat from Spring Boot and adding spring-boot-starter-jetty
made protobuf-java disappear although it's still needed -->
<dependency>
    <groupId>com.google.protobuf</groupId>
    <artifactId>protobuf-java</artifactId>
    <version>3.1.0</version>
</dependency>
person cahen    schedule 23.01.2017