【问题标题】:java.lang.NoClassDefFoundError: com/google/common/base/MoreObjects when initializing pubsub on appenginejava.lang.NoClassDefFoundError: com/google/common/base/MoreObjects 在 appengine 上初始化 pubsub 时
【发布时间】:2023-03-03 08:40:21
【问题描述】:

我尝试在 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)

我该如何解决这个问题?

【问题讨论】:

  • 尝试使用番石榴18.0 or later:jar。

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


【解决方案1】:

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

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

【讨论】:

  • 这个语法对于 Maven 来说已经足够好了。对于 Gradle 尝试:实现组:'com.google.guava',名称:'guava',版本:'18.0' 但是,在我的情况下,这并没有解决 API
猜你喜欢
  • 2018-01-18
  • 2018-05-26
  • 1970-01-01
  • 2023-03-05
  • 2012-04-17
  • 1970-01-01
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多