spring-boot - /graphql 端点在 spring 云应用程序的集成测试期间返回 404 错误,但不是通过使用 mvn spring-boot:run 运行应用程序
问题描述
spring-cloud.version:Greenwich.SR2,spring boot 2.1.7
mvn spring-boot:run 使端点 /graphql 可访问,但不能 mvn clean verify
我包括了 graphql-java-servlet、javax.servlet-api、graphql-spring-boot-starter-test 和 graphql-spring-boot-starter,但它仍然不起作用
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<!-- graphql -->
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
<version>13.0</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-extended-scalars</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>java-dataloader</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>5.10.0</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>5.0.2</version>
</dependency>
<!-- Apache CXF -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
这是我返回 404 的简单测试:
@Test
public void persons() throws Exception {
Map<String, Object> variables = new HashMap<String, Object>();
GraphQLRequest request = new GraphQLRequest(
"query persons{persons"
+ "{"
+ " id"
+ "}}",
variables,
null);
// SUT
given()
.contentType(ContentType.JSON)
.body(request)
.get(GRAPHQL_PATH)
.then()
.log().body()
.statusCode(200);
}
测试类注释为:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations = "classpath:bootstrap-test.yml")
这是我的 bootstrap.yml:
spring:
application:
name: crm-service
cloud:
config:
uri: http://localhost:8081
fail-fast: false
password: configPassword
username: user
main:
allow-bean-definition-overriding: true #i dont remember why but i think there is a bug with spring cloud and OAuth2ClientContext
acls-management:
permissions-config-path: permissions-config.json
acl-rules-path: acl-rules.json
eureka:
client:
register-with-eureka: false
fetch-registry: false
graphql:
servlet:
mapping: /graphql
enabled: true
解决方案
推荐阅读
- c# - 这是什么设计模式?从 byte[] 转换为自己的类型并返回的对象
- javascript - 如何在对象属性中使用来自 JSDoc 的枚举注解
- sql - 存储过程的增量不超过 10 增量
- reactjs - 如何使用 git(使用 http)在 heroku 上推送更改
- r - 将宽数据帧中的值合并到长数据帧中
- oracle - 我可以在不修改 tnsnames.ora 的情况下创建连接吗?
- amazon-web-services - 在 AWS ECS 中设置 ulimit:HardLimit 不能为空
- python - 如何为多列定义变量
- sql - SQL Server 中列值的每行总计
- python - 我收到此代码错误,请任何人纠正并解释我的错误