gpt4 book ai didi

java - Google Cloud KMS java.lang.NoSuchMethodError:com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String; CLjava/lang/Object;)V

转载 作者:行者123 更新时间:2023-12-03 05:33:13 26 4
gpt4 key购买 nike

我正在为KMS使用Java客户端库。 KeyManagementServiceClient.create()方法shown here引发上述异常。

Guava 依赖项看起来还不错-27.1-jre

public String encrypt(String plaintext) throws IOException {
byte[] ciphertext = encrypt(PROJECT_ID, LOCATION_ID, KEYRING_ID, KEY_ID, plaintext.getBytes());
return ciphertext.toString();
}


/**
* Encrypts the given plaintext using the specified crypto key.
*/
private static byte[] encrypt(
String projectId, String locationId, String keyRingId, String cryptoKeyId, byte[] plaintext)
throws IOException {

// Create the KeyManagementServiceClient using try-with-resources to manage client cleanup.
try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {

// The resource name of the cryptoKey
String resourceName = CryptoKeyName.format(projectId, locationId, keyRingId, cryptoKeyId);

// Encrypt the plaintext with Cloud KMS.
EncryptResponse response = client.encrypt(resourceName, ByteString.copyFrom(plaintext));

// Extract the ciphertext from the response.
return response.getCiphertext().toByteArray();
}
}
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V

at io.grpc.Metadata$Key.validateName(Metadata.java:629)
at io.grpc.Metadata$Key.<init>(Metadata.java:637)
at io.grpc.Metadata$Key.<init>(Metadata.java:567)
at io.grpc.Metadata$AsciiKey.<init>(Metadata.java:742)
at io.grpc.Metadata$AsciiKey.<init>(Metadata.java:737)
at io.grpc.Metadata$Key.of(Metadata.java:593)
at io.grpc.Metadata$Key.of(Metadata.java:589)
at com.google.api.gax.grpc.GrpcHeaderInterceptor.<init>(GrpcHeaderInterceptor.java:60)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:220)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:193)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:185)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:160)
at com.google.cloud.kms.v1.stub.GrpcKeyManagementServiceStub.create(GrpcKeyManagementServiceStub.java:370)
at com.google.cloud.kms.v1.stub.KeyManagementServiceStubSettings.createStub(KeyManagementServiceStubSettings.java:333)
at com.google.cloud.kms.v1.KeyManagementServiceClient.<init>(KeyManagementServiceClient.java:155)
at com.google.cloud.kms.v1.KeyManagementServiceClient.create(KeyManagementServiceClient.java:136)
at com.google.cloud.kms.v1.KeyManagementServiceClient.create(KeyManagementServiceClient.java:127)
at com.project.encryption.KmsEncryption.encrypt(KmsEncryption.java:38)
at com.project.KmsEncryption.encrypt(KmsEncryption.java:21)

我希望它返回编码后的字符串,因为命令行指令在相同的项目设置和配置下可以正常工作。

最佳答案

第三方图书馆的问题:

  java.lang.NoSuchMethodError:   com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V
让我们尝试看看 Guava 的依赖性。对我来说,已通过更新 Guava 解决了它:
 <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>

关于java - Google Cloud KMS java.lang.NoSuchMethodError:com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String; CLjava/lang/Object;)V,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58108310/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com