['server.port'和'management.server.port'属性不同时如何测试Spring Boot执行器端点

问题描述 投票:2回答:1

我想借助MockMvc bean测试Spring Boot微服务的/health端点。但是在我的情况下,server.portmanagement.server.port属性具有不同的值。我的GET发出的MockMvc请求始终在server.port中定义的端口上结束。

[已经有一个答案:Spring boot's actuator unavailable when set management port但是我在ManagementContextResolver中找不到此Spring Boot 2.2.2类。

到目前为止,我发现'management'ConfigurableWebServerApplicationContext是在org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration.DifferentManagementContextConfiguration中创建的,但是我看不到如何获得对此的引用。。

spring spring-boot spring-boot-actuator
1个回答
1
投票

尝试一下,它来自SpringBoot Docs:

@WebIntegrationTest({"server.port=8080", "management.port=8090"})
© www.soinside.com 2019 - 2024. All rights reserved.