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
相关产品推荐
相关产品推荐

