我写了一个基于 class 的简单 GraphQL Servlet SimpleGraphQLServlet
。此类的构造函数已弃用,建议改用生成器。所以我所做的是提供我自己的 servlet,它将请求转发到SimpleGraphQLServlet
可以在我的 servletinit
方法中构建的实例:
@WebServlet("/graphql")
public class GraphQLEndpoint extends HttpServlet {
SimpleGraphQLServlet graphQLServlet;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
graphQLServlet.service(req, resp);
}
@Override
public void init() throws ServletException {
graphQLServlet = SimpleGraphQLServlet.builder(buildSchema()).withInstrumentation(new TracingInstrumentation()).build();
}
private GraphQLSchema buildSchema() { /* ... */ }
}
但是,在SimpleGraphQLServlet
创建实例时,会抛出以下异常:
java.lang.NoClassDefFoundError: graphql/execution/instrumentation/NoOpInstrumentation
at graphql.servlet.SimpleGraphQLServlet$Builder.<init>(SimpleGraphQLServlet.java:134) ~[graphql-java-servlet-4.7.0.jar:na]
这很奇怪,因为该类似乎在 jar 文件中可用graphql-java-8.0.jar
。我声明了以下依赖项:
dependencies {
compile "com.graphql-java:graphql-java:8.0"
compile "com.graphql-java:graphql-java-tools:4.3.0"
compile "com.graphql-java:graphql-java-servlet:4.7.0"
compile "org.slf4j:slf4j-simple:1.7.25"
testCompile "junit:junit:3.8.1"
providedCompile "javax.servlet:javax.servlet-api:3.0.1"
}
我错过了什么?