Skip to content

Setting management port causes multiple Tomcat instances to start in tests #2798

@sawano

Description

@sawano

If I set the management port via configuration then a Tomcat will be started listening on that port when running @WebAppConfiguration tests.
I.e. an application.yml with:

management:
  port: 8081

would cause a Tomcat to start on port 8081 when running a test looking like this:

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@SpringApplicationConfiguration(classes = {Application.class})
public class ATest {
...
}

This is not the intended behavior if I am correct or am I missing something?

The implication I am running into (this might be a separate issue) is that if I have two tests with different application contexts then that will cause the second test to fail. Apparently because the loading of the second application context also tries to start a Tomcat on the same port. Which obviously fails.

That is, if the second test looks like:

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@SpringApplicationConfiguration(classes = {Application.class, BTest.Conf.class})
public class BTest {
...
}

then running both ATest and BTest will fail one of them.

So I guess the two questions are

  1. Is a Tomcat for the management port supposed to start in the test?
  2. If so, why is the second application context triggering a start of a new Tomcat?

I put some example code that illustrates this here https://github.com/sawano/spring-boot-management-port-test-issue

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions