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



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

那里已经有一个答案:
设置管理端口
时弹簧靴的执行器不可用,但我在Spring Boot 2.2.2找不到这个ManagementContextResolver类。

到目前为止,我发现"管理"ConfigurableWebServerApplicationContext是在org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration.DifferentManagementContextConfiguration中创建的,但我不明白如何获得对它的引用。

试试这个,它来自 SpringBoot Docs:

@WebIntegrationTest({"server.port=8080", "management.port=8090"})

最新更新