Skip to content

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) is no longer applied to the management server #48653

@pnescior

Description

@pnescior

When using @SpringBootTest with RANDOM_PORT web environment, the tests cannot start when my application is running locally, due to do management port being in use:

[...]
Caused by:
	org.springframework.boot.web.server.PortInUseException: Port 8081 is already in use
		at app//org.springframework.boot.web.server.PortInUseException.lambda$throwIfPortBindingException$0(PortInUseException.java:73)
		at app//org.springframework.boot.web.server.PortInUseException.lambda$ifPortBindingException$0(PortInUseException.java:89)
		at app//org.springframework.boot.web.server.PortInUseException.ifCausedBy(PortInUseException.java:107)
		at app//org.springframework.boot.web.server.PortInUseException.ifPortBindingException(PortInUseException.java:85)
		at app//org.springframework.boot.web.server.PortInUseException.throwIfPortBindingException(PortInUseException.java:72)
		at app//org.springframework.boot.tomcat.TomcatWebServer.start(TomcatWebServer.java:247)
		at app//org.springframework.boot.web.server.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:44)
		at app//org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:420)
		... 51 more
[...]

According to Spring Boot documentation, RANDOM_PORT should take effect also for the management server.

Problem happens in Spring Boot v4.
Here's link to repo with minimal setup for reproduction: https://github.com/pnescior/spring-boot-management-issue

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions