spring-boot: @SpringBootTest(randomPort = true) does not generate random port for actuator
Step by step
- Add the actuator to a web project
- Change the port configuration of the actuator, e.g.
management.port=8081 - Create an integration test that uses the
@WebIntegrationTest(randomPort = true) - Execute the test
Expected result
The actuator endpoints should be assigned to a random port.
Actual result
The actuator endpoints are assigned to the same port as in the configuration file (i.e. 8081 in the example above)
Version
Spring Boot 1.3.0.RC1
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 2
- Comments: 15 (10 by maintainers)
Is there any news with this fix?
@philwebb The problem that I am currently facing is that I cannot have my application running and executing integration tests concurrently because the actuator port collisions when using
randomPort. That said, you are correct, I can use the workaround that you suggested by using@WebIntegrationTest({"server.port=0", "management.port=0"})and then autowire the values in the integration test by using@Value("${local.server.port}")and@Value("${local.management.port}")respectively.Nevertheless, I can see an updated solution to the random port behavior where some logic checks
server.portandmanagement.portin theEnvironment. If justserver.porthas been set (or both have been set and have the same the value) then the random port can be used to generate one single value for both the application and the actuator (thus not affecting any tests that rely on having the same port value). However, if both properties have been specified then two different random values can be generated.I can try help in this issue if not solved, ok @philwebb?