我写了一个基于类SimpleGraphQLServlet
的简单GraphQL Servlet。不推荐使用此类的构造函数,建议使用构建器。所以我所做的就是提供自己的servlet,将请求转发给SimpleGraphQLServlet
的实例,该实例可以在我的servlet的init
方法中构建:
@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"
}
我错过了什么?
答案 0 :(得分:1)
我确实收到了@kaqqao的提示,他告诉我,我的异常是graphql-java版本不匹配。我使用的8.0版本尚不兼容。
现在我使用以下graphql-java依赖项,它工作正常:
function changeletters(str::String)
vowels = "aeiouy"
carr = Vector{Char}(length(str))
i = 0
for c in str
newchar = c == 'z' ? 'a' : c + 1
carr[i+=1] = newchar in vowels ? uppercase(newchar) : newchar
end
return String(carr)
end
@kaqqao关闭评论&#34;覆盖依赖版本是可怕的业务。&#34;。我同意; - )
答案 1 :(得分:0)
2020年答案:
implementation 'com.graphql-java-kickstart:graphiql-spring-boot-starter:5.10.0'
implementation 'com.graphql-java-kickstart:graphql-spring-boot-starter:5.10.0'
implementation 'com.graphql-java-kickstart:graphql-java-tools:5.6.1'
缺少那些依赖项