Skip to content

Embedded Tomcat connector exceptions with Spring boot tests #10366

@murphd40

Description

@murphd40

Description

I'm experiencing a strange exception when I run a test suite:

Caused by: org.springframework.boot.context.embedded.tomcat.ConnectorStartFailedException: 
Connector configured to listen on port 9109 failed to start

The following message is logged:

***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 9109 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 9109, or configure this application to listen on another port.

The root cause seems to be the following:

java.net.BindException: Address already in use

Spring Version

1.5.6.RELEASE


Steps to reproduce

I was able to reproduce the problem with the following classes:

BaseTest

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ApplicationBootstrap.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestPropertySource(locations = "classpath:integration-test.properties")
public abstract class BaseTest {
}

Test1

public class Test1 extends BaseTest {

    @Test
    public void test1() {
        System.out.println("foo");
    }

}

Test2

@TestPropertySource(properties = "NEW_PROPERTY=true")
public class Test2 extends BaseTest {

    @Test
    public void test2() {
        System.out.println("bar");
    }

}

When I run all the tests, Test1 is run first without issue and then it looks as if the application context is refreshed before Test2 is run. Test2 fails with

java.lang.IllegalStateException: Failed to load ApplicationContext

Caused by the ConnectorStartFailedException described above

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions