首次使用GraphQL遇schema.graphqls文件扩展名不识别问题求助
GraphQL schema.graphqls 文件扩展名不被识别问题排查与解决
我首次尝试使用GraphQL,遇到了schema.graphqls文件扩展名不被识别的问题,即使已经在pom.xml中添加了以下依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-graphql</artifactId> </dependency>
以下是几个实用的排查和解决方法:
检查文件存放路径
Spring Boot GraphQL默认会扫描src/main/resources/graphql/目录下的schema文件,务必把schema.graphqls放在这个标准路径下。如果用了自定义目录,需要额外配置路径规则。确认依赖版本兼容性
spring-boot-starter-graphql从Spring Boot 2.6版本开始提供,确保你的Spring Boot主版本和这个starter版本匹配。可以通过Spring Boot父依赖统一管理版本:<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.10</version> <!-- 选择稳定兼容的版本 --> <relativePath/> </parent>手动配置schema规则
如果默认的扩展名或路径不符合你的需求,可以在配置文件中明确指定:
application.properties配置示例:spring.graphql.schema.locations=classpath:graphql/ spring.graphql.schema.file-extensions=graphqls,graphqlapplication.yml配置示例:
spring: graphql: schema: locations: classpath:graphql/ file-extensions: graphqls,graphql刷新项目构建与IDE缓存
有时候IDE缓存或未完成的构建会导致文件不被识别,执行mvn clean install重新构建项目,或者重启IDE刷新缓存后再尝试。
内容的提问来源于stack exchange,提问作者sara
相关产品推荐
相关产品推荐

