我的代码项目框架是springboot+maven,版本是
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-speech</artifactId>
<version>1.24.3</version>
</dependency>
当我使用2.3.0时,代码给了我一个错误。
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-speech</artifactId>
<!-- <version>1.24.3</version>-->
<version>2.3.0</version>
</dependency>
这是错误消息:
Exception in thread "pool-4-thread-1" Exception in thread "pool-3-thread-1" java.lang.NoSuchMethodError: io.grpc.internal.AbstractManagedChannelImplBuilder: method <init>()V not found
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.<init>(NettyChannelBuilder.java:200)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.forTarget(NettyChannelBuilder.java:169)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.forAddress(NettyChannelBuilder.java:152)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:38)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:24)
at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:39)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:350)
at com.google.api.gax.grpc.ChannelPool.<init>(ChannelPool.java:105)
at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:83)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:236)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:230)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:201)
at com.google.cloud.speech.v1p1beta1.stub.GrpcSpeechStub.create(GrpcSpeechStub.java:95)
at com.google.cloud.speech.v1p1beta1.stub.SpeechStubSettings.createStub(SpeechStubSettings.java:133)
at com.google.cloud.speech.v1p1beta1.SpeechClient.<init>(SpeechClient.java:134)
at com.google.cloud.speech.v1p1beta1.SpeechClient.create(SpeechClient.java:116)
at com.google.cloud.speech.v1p1beta1.SpeechClient.create(SpeechClient.java:108)
at com.duplicall.ibaeonline.EngineClients.google.InfiniteStreamRecognize.infiniteStreamingRecognize(InfiniteStreamRecognize.java:95)
at com.duplicall.ibaeonline.EngineClients.google.InfiniteStreamRecognize.lambda$StartTrans$0(InfiniteStreamRecognize.java:291)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
java.lang.NoSuchMethodError: io.grpc.internal.AbstractManagedChannelImplBuilder: method <init>()V not found
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.<init>(NettyChannelBuilder.java:200)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.forTarget(NettyChannelBuilder.java:169)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.forAddress(NettyChannelBuilder.java:152)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:38)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:24)
at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:39)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:350)
at com.google.api.gax.grpc.ChannelPool.<init>(ChannelPool.java:105)
at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:83)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:236)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:230)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:201)
at com.google.cloud.speech.v1p1beta1.stub.GrpcSpeechStub.create(GrpcSpeechStub.java:95)
at com.google.cloud.speech.v1p1beta1.stub.SpeechStubSettings.createStub(SpeechStubSettings.java:133)
at com.google.cloud.speech.v1p1beta1.SpeechClient.<init>(SpeechClient.java:134)
at com.google.cloud.speech.v1p1beta1.SpeechClient.create(SpeechClient.java:116)
at com.google.cloud.speech.v1p1beta1.SpeechClient.create(SpeechClient.java:108)
at com.duplicall.ibaeonline.EngineClients.google.InfiniteStreamRecognize.infiniteStreamingRecognize(InfiniteStreamRecognize.java:95)
at com.duplicall.ibaeonline.EngineClients.google.InfiniteStreamRecognize.lambda$StartTrans$0(InfiniteStreamRecognize.java:291)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
我不知道V1和V2之间的区别。我认为google-cloud-speech版本升级应该是向后兼容的。如果您熟悉该产品请评论
查看官方代码; V1:
public static void asyncStreamingRecognize() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SpeechClient speechClient = SpeechClient.create()) {
BidiStream<StreamingRecognizeRequest, StreamingRecognizeResponse> bidiStream =
speechClient.streamingRecognizeCallable().call();
StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder().build();
bidiStream.send(request);
for (StreamingRecognizeResponse response : bidiStream) {
// Do something when a response is received.
}
}
}
V2:
public static void asyncStreamingRecognize() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SpeechClient speechClient = SpeechClient.create()) {
BidiStream<StreamingRecognizeRequest, StreamingRecognizeResponse> bidiStream =
speechClient.streamingRecognizeCallable().call();
StreamingRecognizeRequest request =
StreamingRecognizeRequest.newBuilder()
.setRecognizer(
RecognizerName.of("[PROJECT]", "[LOCATION]", "[RECOGNIZER]").toString())
.build();
bidiStream.send(request);
for (StreamingRecognizeResponse response : bidiStream) {
// Do something when a response is received.
}
}
}
这和maven引用的版本有关系吗?