Spring Boot 2.2.5(Java 8)环境下GraphQL服务无法暴露且访问404的问题求助
Spring Boot 2.2.5(Java 8)环境下GraphQL服务无法暴露且访问404的问题求助
大家好,我最近在搭建Spring Boot+GraphQL服务时碰到了棘手的问题,访问/graphql路径一直返回404,想请各位帮忙分析下问题出在哪。
我的环境与依赖配置
当前应用运行在Java 8和Spring Boot 2.2.5.RELEASE环境下,用来搭建GraphQL服务的Maven依赖如下:
<dependency> <groupId>com.graphql-java-kickstart</groupId> <artifactId>graphql-spring-boot-starter</artifactId> <version>${graphql.version}</version> </dependency> <dependency> <groupId>com.graphql-java-kickstart</groupId> <artifactId>graphql-java-tools</artifactId> <version>${graphql.version}</version> </dependency> <dependency> <groupId>com.graphql-java-kickstart</groupId> <artifactId>graphiql-spring-boot-starter</artifactId> <version>${graphql.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
GraphQL Schema定义
我把Schema文件放在了src/main/resources/graphql/mobile.graphqls,内容如下:
type Mobile { msisdn: String! iccid: String! } type Query { loadMobileByKey(msisdn: String!, iccid: String!): Mobile }
Query Resolver实现
对应的查询Resolver类已经添加了@Component注解,确保能被Spring扫描到,代码如下:
@Component public class MobileController implements GraphQLQueryResolver { private static final Logger LOGGER = LoggerFactory.getLogger(MobileController.class); @PostConstruct public void test(){ LOGGER.info("Bean MobileController initialized"); } public Mobile loadMobileByKey(String msisdn,String iccid) { return new Mobile(msisdn,iccid); } }
日志中的异常信息
我开启了DEBUG级别的日志,发现自动配置的条件评估报告里有几个关键的不匹配项,具体日志内容如下:
============================ CONDITIONS EVALUATION REPORT ============================ Negative matches: ----------------- GraphQLJavaToolsAutoConfiguration: Did not match: - @ConditionalOnClass did not find required class 'com.coxautodev.graphql.tools.SchemaParser' (OnClassCondition) GraphQLWebAutoConfiguration: Did not match: - AnyNestedCondition 0 matched 2 did not; NestedCondition on OnSchemaOrSchemaProviderBean.OnSchemaProvider @ConditionalOnBean (types: graphql.kickstart.execution.config.GraphQLSchemaProvider; SearchStrategy: all) did not find any beans of type graphql.kickstart.execution.config.GraphQLSchemaProvider; NestedCondition on OnSchemaOrSchemaProviderBean.OnSchema @ConditionalOnBean (types: graphql.schema.GraphQLSchema; SearchStrategy: all) did not find any beans of type graphql.schema.GraphQLSchema (OnSchemaOrSchemaProviderBean) Matched: - @ConditionalOnClass found required class 'org.springframework.web.servlet.DispatcherServlet' (OnClassCondition) - @ConditionalOnWebApplication (required) found 'session' scope (OnWebApplicationCondition) - @ConditionalOnProperty (graphql.servlet.enabled=true) matched (OnPropertyCondition) Positive matches: ----------------- GraphQLInstrumentationAutoConfiguration matched: - @ConditionalOnClass found required class 'org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration' (OnClassCondition) - @ConditionalOnProperty (graphql.servlet.enabled=true) matched (OnPropertyCondition) GraphiQLAutoConfiguration matched: - @ConditionalOnClass found required class 'org.springframework.web.servlet.DispatcherServlet' (OnClassCondition) - @ConditionalOnWebApplication (required) found 'session' scope (OnWebApplicationCondition) GraphiQLAutoConfiguration#graphiQLController matched: - @ConditionalOnProperty (graphiql.enabled=true) matched (OnPropertyCondition)
访问时的404错误
不管是用Postman请求/graphql接口,还是通过浏览器打开GraphiQL IDE访问,都会返回404错误,响应内容如下:
{ "timestamp": "2025-08-28T14:08:18.360+0000", "status": 404, "error": "Not Found", "message": "No message available", "path": "/graphql" }
有没有大佬能帮忙看看问题根源?怎么才能让GraphQL服务正常暴露并访问呢?
内容来源于stack exchange
相关产品推荐
相关产品推荐

