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

Spring Boot 3+Spring GraphQL测试时/graphql端点未暴露求助

问题:Spring GraphQL测试环境下/graphql端点返回404错误

环境信息

  • 技术栈:Java 17 + Spring Boot 3.0.5 + Spring GraphQL

问题现象

生产环境运行正常,可通过GraphiQL或Postman正常执行GraphQL查询与变更操作;但运行测试用例时,/graphql端点未暴露,请求返回404错误。

错误日志

2023-04-14 | 12:15:37.783 | main                 | ERROR | ExchangeResult.assertWithDiagnostics - Request details for assertion failure:

> POST http://localhost:57947/graphql
> accept-encoding: [gzip]
> user-agent: [ReactorNetty/1.1.5]
> host: [localhost:57947]
> WebTestClient-Request-Id: [1]
> Content-Type: [application/json]
> Accept: [application/json]
> Content-Length: [180]

{"query":"myGraphQLQuery(\n    source:{countryCode:\"GB\", locale:\"en-US\"},\n    amount:{value:\"150.00\", currency:\"GBP\"}\n) {\n    provider\n    method\n    specifics\n}"}

< 404 NOT_FOUND Not Found < Date: [Fri, 14 Apr 2023 11:15:37 GMT] < Content-Type: [application/json] < Content-Length: [116]

{"timestamp":1681470937706,"path":"/graphql","status":404,"error":"Not Found","message":null,"requestId":"2c691d2e"}


java.lang.AssertionError: Status expected:<200 OK> but was:<404 NOT_FOUND>

日志对比

与生产正常运行的日志相比,测试日志中缺少了GraphQlWebFluxAutoConfiguration.? - GraphQL endpoint HTTP POST /graphql这一行。

测试代码

package com.mycompany.test;

import com.mycompany.MyApplication;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureGraphQlTester;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@Slf4j
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = MyApplication.class)
@AutoConfigureGraphQlTester
public class MyGraphqlTest {

    @Autowired
    protected GraphQlTester graphQlTester;

    @Test
    public void test() {
        GraphQlTester.Request<?> myGraphQLQuery = graphQlTester.documentName("myGraphQLQueryFile");
        GraphQlTester.Response response = myGraphQLQuery.execute();
        System.out.println(response);
    }
}

请问有人知道这个问题的原因吗?感谢!


内容的提问来源于stack exchange,提问作者SERGIO STATERI JUNIOR

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 18:45:21