Ошибка разбора схемы graphql в Springboot, как это исправить? - PullRequest
1 голос
/ 01 октября 2019

У меня есть проект, в котором я использую Springboot с GraphQL.

Я использую Java11 с Gradle 5.6.2.

В своем модуле я добавил эти зависимости для GraphQl.

    // GraphQl
    implementation 'com.graphql-java-kickstart:graphql-spring-boot-starter:5.10.0'
    implementation 'com.graphql-java:graphiql-spring-boot-starter:5.0.2'
    implementation 'com.graphql-java-kickstart:voyager-spring-boot-starter:5.10.0'
    implementation 'com.graphql-java-kickstart:graphql-java-tools:5.6.1'

В моем src/main/java/no.domain.project у меня есть приложение Springboot. У меня также есть папка с именем RootResolver, в которую я добавил следующий класс:

@Component
public class RootResolver implements GraphQLQueryResolver{

    public String getHello() {
        return "Hello World";
    }
}

Мой schema.graphqls имеет следующий запрос:

type Query {
    hello: String!
}

Я могу получить доступ к localhost:8080/grapiql с помощью 404.

Но когда я запускаю проект, я получаю следующие ошибки:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLServletRegistrationBean' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLServletRegistrationBean' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLHttpServlet' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLHttpServlet' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLServletConfiguration' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLServletConfiguration' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'invocationInputFactory' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'invocationInputFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLSchemaProvider' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLSchemaProvider' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration': Unsatisfied dependency expressed through field 'options'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaParserOptions' defined in no.inmeta.ris.web.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.coxautodev.graphql.tools.SchemaParserOptions]: Factory method 'schemaParserOptions' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/coroutines/ContinuationInterceptor

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLHttpServlet' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLHttpServlet' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLServletConfiguration' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLServletConfiguration' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'invocationInputFactory' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'invocationInputFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLSchemaProvider' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLSchemaProvider' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration': Unsatisfied dependency expressed through field 'options'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaParserOptions' defined in no.inmeta.ris.web.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.coxautodev.graphql.tools.SchemaParserOptions]: Factory method 'schemaParserOptions' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/coroutines/ContinuationInterceptor

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLServletConfiguration' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLServletConfiguration' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'invocationInputFactory' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'invocationInputFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLSchemaProvider' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLSchemaProvider' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration': Unsatisfied dependency expressed through field 'options'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaParserOptions' defined in no.inmeta.ris.web.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.coxautodev.graphql.tools.SchemaParserOptions]: Factory method 'schemaParserOptions' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/coroutines/ContinuationInterceptor

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'invocationInputFactory' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'invocationInputFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLSchemaProvider' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLSchemaProvider' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration': Unsatisfied dependency expressed through field 'options'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaParserOptions' defined in no.inmeta.ris.web.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.coxautodev.graphql.tools.SchemaParserOptions]: Factory method 'schemaParserOptions' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/coroutines/ContinuationInterceptor

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLSchemaProvider' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLSchemaProvider' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration': Unsatisfied dependency expressed through field 'options'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaParserOptions' defined in no.inmeta.ris.web.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.coxautodev.graphql.tools.SchemaParserOptions]: Factory method 'schemaParserOptions' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/coroutines/ContinuationInterceptor

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration': Unsatisfied dependency expressed through field 'options'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaParserOptions' defined in no.inmeta.ris.web.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.coxautodev.graphql.tools.SchemaParserOptions]: Factory method 'schemaParserOptions' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/coroutines/ContinuationInterceptor

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaParserOptions' defined in no.inmeta.ris.web.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.coxautodev.graphql.tools.SchemaParserOptions]: Factory method 'schemaParserOptions' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/coroutines/ContinuationInterceptor

Я замкнул сообщение об ошибке.

В чем причина этой проблемы. Я вижу, что это не соответствует моей схеме, но почему это так? Я видел много уроков, где я делаю то же самое, но я получаю эту ошибку.

Любой совет?

Спасибо за помощь!

1 Ответ

2 голосов
/ 01 октября 2019

Я понял :) Мне нужно было добавить файл gradle.properties и добавить kotlin.version=1.3.50, потому что при запуске SpringApplication вы получите ошибку NoClassDefFoundException, потому что SpringBoot перезаписывает версию Kotlin, которую использует библиотека.

...