java.lang.NoSuchMethodError:javax.json.stream.JsonGenerator.writeKey(Ljava/lang/String;)Ljavax/json/stream/JsonGenerator;

问题描述 投票:0回答:1

我正在尝试将一个简单的 graphql 服务部署到 java ee 7 服务器以证明它可以完成。 我管理 jakarta ee 10 版本的工作,但 java ee 7 版本已部署并运行,但当我使用

测试 Web 服务时
  curl -X POST -H "Content-Type: application/json" -d '{"query": "query { hello }"}' http://localhost:8080/deneme2-web/graphql/graphql

它在运行时吐出这个堆栈跟踪

14:50:54,878 SEVERE [org.eclipse.yasson.internal.Marshaller] (default task-2) Generating incomplete JSON
14:50:54,881 ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /deneme2-web/graphql/graphql: java.lang.NoSuchMethodError: javax.json.stream.JsonGenerator.writeKey(Ljava/lang/String;)Ljavax/json/stream/JsonGenerator;
    at org.eclipse.yasson.internal.serializer.MapSerializer.serializeInternal(MapSerializer.java:56)
    at org.eclipse.yasson.internal.serializer.MapSerializer.serializeInternal(MapSerializer.java:32)
    at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:64)
    at org.eclipse.yasson.internal.Marshaller.serializeRoot(Marshaller.java:119)
    at org.eclipse.yasson.internal.Marshaller.marshall(Marshaller.java:75)
    at org.eclipse.yasson.internal.JsonBinding.toJson(JsonBinding.java:98)
    at io.smallrye.graphql.execution.ExecutionService.toJsonValue(ExecutionService.java:119)
    at io.smallrye.graphql.execution.ExecutionService.addDataToResponse(ExecutionService.java:92)
    at io.smallrye.graphql.execution.ExecutionService.addDataToResponse(ExecutionService.java:87)
    at io.smallrye.graphql.execution.ExecutionService.execute(ExecutionService.java:75)
    at io.smallrye.graphql.servlet.ExecutionServlet.handleInput(ExecutionServlet.java:79)
    at io.smallrye.graphql.servlet.ExecutionServlet.doPost(ExecutionServlet.java:64)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
    at java.lang.Thread.run(Thread.java:750)

这也是我的 pom 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>deneme2</artifactId>
        <groupId>deneme2</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>deneme2-web</artifactId>
    <packaging>war</packaging>

    <name>deneme2: WAR Module</name>

    <url>http://wildfly.org</url>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <distribution>repo</distribution>
            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
        </license>
    </licenses>

    <dependencies>

        <!-- Dependency on the EJB module so we can use it's services if needed -->
        <dependency>
            <groupId>deneme2</groupId>
            <artifactId>deneme2-ejb</artifactId>
            <type>ejb</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.json.bind</groupId>
            <artifactId>javax.json.bind-api</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse</groupId>
            <artifactId>yasson</artifactId>
            <version>1.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.json</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.microprofile.graphql</groupId>
            <artifactId>microprofile-graphql-api</artifactId>
            <version>1.1.0</version><project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>deneme2</artifactId>
        <groupId>deneme2</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>deneme2-web</artifactId>
    <packaging>war</packaging>

    <name>deneme2: WAR Module</name>

    <url>http://wildfly.org</url>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <distribution>repo</distribution>
            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
        </license>
    </licenses>

    <dependencies>

        <!-- Dependency on the EJB module so we can use it's services if needed -->
        <dependency>
            <groupId>deneme2</groupId>
            <artifactId>deneme2-ejb</artifactId>
            <type>ejb</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.json.bind</groupId>
            <artifactId>javax.json.bind-api</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse</groupId>
            <artifactId>yasson</artifactId>
            <version>1.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.json</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.microprofile.graphql</groupId>
            <artifactId>microprofile-graphql-api</artifactId>
            <version>1.1.0</version>
        </dependency>

        <!--
        https://mvnrepository.com/artifact/org.eclipse.microprofile.config/microprofile-config-api -->
        <dependency>
            <groupId>org.eclipse.microprofile.config</groupId>
            <artifactId>microprofile-config-api</artifactId>
            <version>1.4</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.smallrye/smallrye-config -->
        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-config</artifactId>
            <version>1.4.0</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/io.smallrye/smallrye-graphql-api -->
        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-graphql-api</artifactId>
            <version>1.0.1</version>
        </dependency>
        <!--
        https://mvnrepository.com/artifact/io.smallrye/smallrye-graphql-servlet -->
        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-graphql-servlet</artifactId>
            <version>1.0.1</version>
        </dependency>

        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-graphql</artifactId>
            <version>1.0.1</version>
        </dependency>


    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>${version.war.plugin}</version>
                <configuration>
                    <!-- Java EE 7 doesn't require web.xml, Maven needs to catch
                    up! -->
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
        </dependency>

        <!--
        https://mvnrepository.com/artifact/org.eclipse.microprofile.config/microprofile-config-api -->
        <dependency>
            <groupId>org.eclipse.microprofile.config</groupId>
            <artifactId>microprofile-config-api</artifactId>
            <version>1.4</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.smallrye/smallrye-config -->
        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-config</artifactId>
            <version>1.4.0</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/io.smallrye/smallrye-graphql-api -->
        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-graphql-api</artifactId>
            <version>1.0.1</version>
        </dependency>
        <!--
        https://mvnrepository.com/artifact/io.smallrye/smallrye-graphql-servlet -->
        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-graphql-servlet</artifactId>
            <version>1.0.1</version>
        </dependency>

        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-graphql</artifactId>
            <version>1.0.1</version>
        </dependency>


    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>${version.war.plugin}</version>
                <configuration>
                    <!-- Java EE 7 doesn't require web.xml, Maven needs to catch
                    up! -->
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

这里是勇敢灵魂的重现器:https://github.com/urbandroid/graphql-jakarta/tree/javaee7

java json jakarta-ee java-ee-7
1个回答
0
投票

您需要在 pom.xml 中添加

javax.json-api
依赖项:

<dependency>
    <groupId>javax.json</groupId>
    <artifactId>javax.json-api</artifactId>
    <version>1.1.4</version>
</dependency>

此依赖项具有类

javax.json.stream.JsonGenerator
,该类具有此方法
writeKey(String name)

© www.soinside.com 2019 - 2024. All rights reserved.