java.lang.NoClassDefFoundError:com / google / common / base / MoreObjects在appengine上初始化pubsub时

时间:2017-07-11 17:57:18

标签: 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)

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:9)

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

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