AppEngine标准Java8中的Google PubSub错误:java.lang.NoSuchFieldError:CONTEXT\u SPAN\u KEY

AppEngine标准Java8中的Google PubSub错误:java.lang.NoSuchFieldError:CONTEXT\u SPAN\u KEY,java,google-app-engine,publish-subscribe,grpc,Java,Google App Engine,Publish Subscribe,Grpc,我有一个在AppEngine标准Java8上运行的Web应用程序。该应用程序需要将消息发布到Google PubSub。每当执行此行时: ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage); pom.xml <project> <modelVersion>4.0.0</modelVersion> <packaging>war</packagin

我有一个在AppEngine标准Java8上运行的Web应用程序。该应用程序需要将消息发布到Google PubSub。每当执行此行时:

ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage);
pom.xml

<project>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<groupId>com.example.test</groupId>
<artifactId>appengine-pubsub</artifactId>
<prerequisites>
    <maven>3.0</maven>
</prerequisites>

<properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <endpoints.framework.version>2.1.2</endpoints.framework.version>
    <endpoints.management.version>1.0.10</endpoints.management.version>

    <google.datastore.version>1.38.0</google.datastore.version>

    <io.netty.all>5.0.0.Alpha2</io.netty.all>

    <endpoints.project.id>my-very-first-project-id</endpoints.project.id>
</properties>

<dependencies>
    <!-- Google -->
    <dependency>
        <groupId>com.google.endpoints</groupId>
        <artifactId>endpoints-framework</artifactId>
        <version>${endpoints.framework.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.endpoints</groupId>
        <artifactId>endpoints-management-control-appengine-all</artifactId>
        <version>${endpoints.management.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.endpoints</groupId>
        <artifactId>endpoints-management-control-appengine</artifactId>
        <version>${endpoints.management.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.endpoints</groupId>
        <artifactId>endpoints-framework-auth</artifactId>
        <version>${endpoints.management.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>1.9.64</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-pubsub -->
    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-pubsub</artifactId>
        <version>0.48.0-beta</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.5</version>
    </dependency>
    <!-- javax -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <type>jar</type>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.json/json -->
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20180813</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.1.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java -->
    <dependency>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java</artifactId>
        <version>3.6.1</version>
    </dependency>

</dependencies>

<build>
    <!-- for hot reload of the web application-->
    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes
    </outputDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <webResources>
                    <resources>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resources>
                </webResources>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>1.3.2</version>
            <configuration>
                <!-- deploy configuration -->
                <hostname>${endpoints.project.id}.appspot.com</hostname>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>endpoints-framework-maven-plugin</artifactId>
            <version>1.0.2</version>
            <configuration>
                <!-- plugin configuration -->
                <hostname>${endpoints.project.id}.appspot.com</hostname>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>display-dependency-updates</goal>
                        <goal>display-plugin-updates</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

在逐个筛选出库之后,我能够找到原因。我从pom.xml中删除了端点管理控制appengine,PubSub从我的本地服务器开始工作

<dependency>
    <groupId>com.google.endpoints</groupId>
    <artifactId>endpoints-management-control-appengine-all</artifactId>
    <version>${endpoints.management.version}</version>
</dependency>

谢谢大家

使用pubsub发布时,我遇到了一个类似的错误。1.52.0依赖于云端点appengine标准上的opencensus 0.12.3,通过将opencensus api 0.18.0设置为单独的依赖项并将其从google cloud pubsub依赖项中排除,解决了这个问题

    <!-- https://mvnrepository.com/artifact/io.opencensus/opencensus-api -->
<dependency>
    <groupId>io.opencensus</groupId>
    <artifactId>opencensus-api</artifactId>
    <version>0.18.0</version>
</dependency>    

<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-pubsub -->
                <dependency>
                    <groupId>com.google.cloud</groupId>
                    <artifactId>google-cloud-pubsub</artifactId>
                    <version>1.52.0</version>
                    <exclusions>
                        <exclusion>
                            <groupId>io.opencensus</groupId>
                            <artifactId>opencensus-api</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>

您能分享您的pom.xml和完整的错误消息跟踪吗?这样我们就可以更好地了解失败时的情况了?@PhilippSh感谢您的回复!通过添加上面的pom.xml编辑了这篇文章。查看pom.xml,事情看起来不错,您应该使用opencensus 0.11.0。但是pom.xml也是不完整的;您可能有一个父pom或类似的pom,可以更改依赖项。我建议你试着运行mvn dependency:tree,看看opencensus有哪些版本。谢谢@Eric Anderson!更新了pom.xml,没有父pom。运行mvn dependecy:tree并返回opencensus-api-0.12.3.jar,更改为0.11.0,但仍然看不到io.opencensus.trace.unsafe.ContextUtils.CONTEXT\u SPAN\u键
    <!-- https://mvnrepository.com/artifact/io.opencensus/opencensus-api -->
<dependency>
    <groupId>io.opencensus</groupId>
    <artifactId>opencensus-api</artifactId>
    <version>0.18.0</version>
</dependency>    

<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-pubsub -->
                <dependency>
                    <groupId>com.google.cloud</groupId>
                    <artifactId>google-cloud-pubsub</artifactId>
                    <version>1.52.0</version>
                    <exclusions>
                        <exclusion>
                            <groupId>io.opencensus</groupId>
                            <artifactId>opencensus-api</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>