You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring-GraphQL如何配置外部JAR中schema.graphqls的路径

解决Spring-GraphQL加载外部JAR中Schema文件的配置问题

正确配置路径

你需要将spring.graphql.schema.locations设置为classpath:/,若需要明确文件扩展名,可配合spring.graphql.schema.file-extensions(默认已支持.graphqls等后缀,也可按需指定)。

application.yml配置示例

spring:
  graphql:
    schema:
      locations: "classpath:/"
      file-extensions: graphqls,graphql,gql,gqls

application.properties配置示例

spring.graphql.schema.locations=classpath:/
spring.graphql.schema.file-extensions=graphqls,graphql,gql,gqls

配置逻辑说明

  • classpath:/指向类路径的根目录,从你提供的URIjar:...!/schema.graphqls能看出,schema文件正好位于外部JAR的类路径根目录下(!/后直接是文件名),因此该路径能精准扫描到目标文件。
  • 你之前尝试的classpath:**无效,是因为Spring-GraphQL的locations属性要求填写目录路径,而非Ant风格的文件通配符。如果需要更精准匹配单个文件,可结合pattern属性:
spring:
  graphql:
    schema:
      locations: "classpath:/"
      pattern: "schema.graphqls"

内容的提问来源于stack exchange,提问作者Michiel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 20:39:52