【问题标题】:Spring boot graphql No graphql schema files found on classpathSpring boot graphql 在类路径中找不到 graphql 模式文件
【发布时间】:2021-12-14 09:52:32
【问题描述】:

我使用 mongodb、spring-boot 和 graphql 开发了一个后端应用程序。我正在使用 Jetbrains IDEA IDE。项目可以在我的开发机器上运行,但不能在另一台计算机上运行。 Graphql 报错。

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaParser' defined in class path resource [graphql/kickstart/autoconfigure/tools/GraphQLJavaToolsAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.kickstart.tools.SchemaParser]: Factory method 'schemaParser' threw exception; nested exception is java.lang.IllegalStateException: No graphql schema files found on classpath with location pattern '"**/*.graphql"'.  Please add a graphql schema to the classpath or add a SchemaParser bean to your application context

首先,我将我的项目打包为 jar 文件。我试图运行它并得到同样的错误。 因此,我克隆了我的项目并从源代码构建它,并尝试直接从源代码运行。但是又抛出了同样的错误。

我的应用程序.yml

graphql:
  tools:
    schema-location-pattern: "**/*.graphql"
  playground:
    enabled: true
  servlet:
    max-query-depth: 5
    exception-handlers-enabled: true

我的 pom.xml 依赖和构建部分

<dependencies>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver-sync</artifactId>
            <version>4.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver-core</artifactId>
            <version>4.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>bson</artifactId>
            <version>4.3.1</version>
        </dependency>

        <dependency>
            <groupId>com.graphql-java-kickstart</groupId>
            <artifactId>graphql-spring-boot-starter</artifactId>
            <version>12.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.graphql-java-kickstart</groupId>
            <artifactId>graphql-java-tools</artifactId>
            <version>12.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.graphql-java-kickstart</groupId>
            <artifactId>voyager-spring-boot-starter</artifactId>
            <version>11.1.0</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.12.85</version>
        </dependency>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-storage</artifactId>
            <version>2.1.7</version>
        </dependency>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-translate</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-security</artifactId>
                </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>2.4.4</version>
        </dependency>
        <dependency>
            <groupId>com.github.javafaker</groupId>
            <artifactId>javafaker</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.1.3</version>
        </dependency>
    </dependencies>

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>apt-maven-plugin</artifactId>
                <version>1.1.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/generated-sources/java</outputDirectory>
                            <processor>com.querydsl.mongodb.morphia.MorphiaAnnotationProcessor</processor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.asciidoctor</groupId>
                <artifactId>asciidoctor-maven-plugin</artifactId>
                <version>1.5.8</version>
                <executions>
                    <execution>
                        <id>generate-docs</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>process-asciidoc</goal>
                        </goals>
                        <configuration>
                            <backend>html</backend>
                            <doctype>book</doctype>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.restdocs</groupId>
                        <artifactId>spring-restdocs-asciidoctor</artifactId>
                        <version>${spring-restdocs.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

【问题讨论】:

  • 我对 GraphQL 一无所知,但错误文本“No graphql schema files found on classpath”是否暗示了解决方案?
  • 是的,我搜索了它,但我没有找到任何解决方案。我正确地编辑了我的问题标题。

标签: java spring spring-boot graphql


【解决方案1】:

正如例外情况所说,您没有定义任何架构或者它们是错误的!

No graphql schema files found on classpath with location pattern '"**/*.graphql"'.  Please add a graphql schema to the classpath or add a SchemaParser bean to your application context

【讨论】:

  • 我在资源文件夹下有架构文件,我检查了很多次,项目在我的电脑上运行正常。
  • 你有什么想法,为什么找不到它们?
  • 我想我解决了这个问题,方法是从 application.yml 中删除 schema-location-pattern,并将扩展名从 *.graphlq 更改为 *.graphqls。现在项目可以工作了。
  • 这是以 java graphql 模式结尾的普通文件。但是您仍然可以实现自定义模式解析器,因此您可以使用标准的 graphql 文件结尾。
【解决方案2】:

您可以通过以下方式更改 Kickstarter 依赖项

compile group: 'com.graphql-java', name: 'graphql-spring-boot-starter', version: 
'5.0.2'
compile group: 'com.graphql-java', name: 'graphql-java-tools', version: '5.2.4'
compile group: 'com.graphql-java', name: 'graphiql-spring-boot-starter', version: 
'3.0.3'

【讨论】:

    【解决方案3】:

    在这部分 No graphql schema files found on classpath with location pattern '"**/*.graphql"' 你可以看到",是什么破坏了路径。它应该解决。请记住,路径是相对于resources 文件夹的。

    【讨论】:

      【解决方案4】:

      我解决了这个问题,方法是从 application.yml 中删除 schema-location-pattern,并将扩展名从 *.graphlq 更改为 *.graphqls。现在项目可以工作了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-11-16
        • 2021-01-02
        • 2020-02-13
        • 2020-06-06
        • 2018-12-21
        • 2018-06-11
        • 2012-11-01
        • 2021-02-07
        相关资源
        最近更新 更多