java.lang.NoClassDefFoundError : com/google/common/base/MoreObjects when initializing pubsub on appengine 错误

标签 java google-app-engine java-8 publish-subscribe google-cloud-pubsub

我尝试在 appEngine 上运行这段代码(在我的 web.xml 中定义了 java8)

public TopicName createTopic(final String topicNameStr) throws Exception {
    checkInit();

    final TopicAdminSettings topicAdminSettings =
            TopicAdminSettings.defaultBuilder()
                    .setChannelProvider(channelProvider)
                    .build();

    TopicName topicName = TopicName.create(projectId, topicNameStr);

    try (final TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings)) {
        topicAdminClient.createTopic(topicName);
    }
    return topicName;
}

我得到这个错误:

Uncaught exception from servlet
java.lang.NoClassDefFoundError: com/google/common/base/MoreObjects
    at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:284)
    at com.google.api.gax.grpc.InstantiatingChannelProvider.createChannel(InstantiatingChannelProvider.java:135)
    at com.google.api.gax.grpc.InstantiatingChannelProvider.getChannel(InstantiatingChannelProvider.java:116)
    at com.google.api.gax.grpc.ChannelAndExecutor.create(ChannelAndExecutor.java:65)
    at com.google.api.gax.grpc.ClientSettings.getChannelAndExecutor(ClientSettings.java:77)
    at com.google.cloud.pubsub.spi.v1.TopicAdminClient.<init>(TopicAdminClient.java:150)
    at com.google.cloud.pubsub.spi.v1.TopicAdminClient.create(TopicAdminClient.java:141)
    at linqmap.cloud.google.pubsub.PubSubFactory.createTopic(PubSubFactory.java:142)

我该如何解决这个问题?

最佳答案

尝试使用 guava 18.0 或更高版本这将解决问题。

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>18.0</version>
</dependency>

关于java.lang.NoClassDefFoundError : com/google/common/base/MoreObjects when initializing pubsub on appengine 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45041554/

相关文章:

java - Android:无法请求以反斜杠结尾的 URL

java - MapReduce reducer 错误输出

file - 从 AppEngine 部署中删除不需要的上传

java - google appengine 中 java 后端的示例代码

java - java 8中静态变量存储在哪里?

java - bash 在命令中强制使用双引号

java - 当我调用 fillRoundRect() 时只有 1 个角是圆的

python - 使用 get_current_user() 方法时产生此 python AttributeError 的原因是什么?

Java 8 : Syntax for Implementing java. util.function.Function 作为 Lambda 表达式

java - 为什么 Java 8 泛型类型推断选择这个重载?