在Springboot中使用最新的Netflix DGS物料清单时出错

slhcrj9b  于 2022-10-30  发布在  Spring
关注(0)|答案(1)|浏览(139)

我正在尝试在Springboot中使用Netflix DGS库,并已经按照文档开始使用。
当前状态是,如果我不将DGS作为依赖项,则应用程序与Rest Controller配合使用时工作正常。
我的目标是构建一个Graphql应用程序,它至少可以完成以下任务:

  • 使用schema创建自动生成的类
  • 使用查询和变异构建基本的CRUD操作。

当我尝试运行应用程序时,我得到以下错误:

2022-10-25 17:42:07.757  WARN 9856 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dgsQueryExecutor' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'dgsQueryExecutor' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schema' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'schema' threw exception; nested exception is java.lang.NoSuchMethodError: graphql/schema/idl/RuntimeWiring.transform(Ljava/util/function/Consumer;)Lgraphql/schema/idl/RuntimeWiring; (loaded from file:<HOME_DIR>/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/18.3/d30b46b4db4818fc6547d233b7aef5af6dcfe715/graphql-java-18.3.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@5828c5f9) called from class com.apollographql.federation.graphqljava.Federation (loaded from file:<HOME_DIR>/.gradle/caches/modules-2/files-2.1/com.apollographql.federation/federation-graphql-java-support/2.1.0/9ef0abf955406d2573e84990c05bc3fcb4b2404a/federation-graphql-java-support-2.1.0.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@5828c5f9).
2022-10-25 17:42:07.762  INFO 9856 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-10-25 17:42:07.788  INFO 9856 --- [           main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-10-25 17:42:07.810 ERROR 9856 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************

APPLICATION FAILED TO START

***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

com.apollographql.federation.graphqljava.Federation.ensureFederationDirectiveDefinitionsExist(Federation.java:194)

The following method did not exist:

        graphql/schema/idl/RuntimeWiring.transform(Ljava/util/function/Consumer;)Lgraphql/schema/idl/RuntimeWiring;

The calling method's class, com.apollographql.federation.graphqljava.Federation, was loaded from the following location:

jar:file:<HOME_DIR>/.gradle/caches/modules-2/files-2.1/com.apollographql.federation/federation-graphql-java-support/2.1.0/9ef0abf955406d2573e84990c05bc3fcb4b2404a/federation-graphql-java-support-2.1.0.jar!/com/apollographql/federation/graphqljava/Federation.class

The called method's class, graphql.schema.idl.RuntimeWiring, is available from the following locations:

jar:file:<HOME_DIR>/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/18.3/d30b46b4db4818fc6547d233b7aef5af6dcfe715/graphql-java-18.3.jar!/graphql/schema/idl/RuntimeWiring.class

The called method's class hierarchy was loaded from the following locations:

graphql.schema.idl.RuntimeWiring: file:<HOME_DIR>/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/18.3/d30b46b4db4818fc6547d233b7aef5af6dcfe715/graphql-java-18.3.jar

Action:

Correct the classpath of your application so that it contains compatible versions of the classes com.apollographql.federation.graphqljava.Federation and graphql.schema.idl.RuntimeWiring

        > Task :InventoryApplication.main() FAILED

下面是我正在使用的build.gradle

plugins {
    id 'org.springframework.boot' version '2.7.5'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
    id 'java'
    id "com.netflix.dgs.codegen" version "5.2.4"
    id "org.sonarqube" version "3.4.0.2513"
}

sonarqube {
    properties {
        property "sonar.projectKey", "ArvindSinghRawat_E-Commerce-Inventory"
        property "sonar.organization", "e-commerce"
        property "sonar.host.url", "https://sonarcloud.io"
    }
}

generateJava {
    schemaPaths = ["${projectDir}/src/main/resources/schema"]
    // List of directories containing schema files
    packageName = 'com.personal.inventory.dto.graphql'
    // The package name to use to generate sources
    generateClient = false // Enable generating the type safe query API
    typeMapping = ["BigDecimal": "java.math.BigDecimal"]
}

compileJava {
    options.compilerArgs += ['-Amapstruct.defaultComponentModel=spring',
                             '-Amapstruct.defaultInjectionStrategy']
}

group = 'com.personal'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

ext['kotlin.version'] = '1.4.31'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
//    GraphQL dependencies
    implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:latest.release"))
    implementation "com.netflix.graphql.dgs:graphql-dgs-webflux-starter"
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
    implementation 'org.mapstruct:mapstruct:1.5.3.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
    testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
}

tasks.named('test') {
    useJUnitPlatform()
}

如果我错过了什么,请一定要让我知道。

zf9nrax1

zf9nrax11#

尝试在您的gradle构建脚本中添加以下行:

dependencyManagement {
    imports {
        mavenBom 'com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:latest.release'
    }
}

检查有关问题的问题:https://github.com/Netflix/dgs-framework/issues/1281#issuecomment-1284694300

相关问题