Skip to content

Tomcat fails to start with "factory already defined" error if two integration test harnesses start spring boot as part of the same maven multi-module build (JVM instance) #10617

@jamiecramb

Description

@jamiecramb

We use spring boot as a way to run an embedded tomcat / spring app inside of a JBehave integration test harness.

When in a multi-module maven reactor build we have noticed that if there are 2 modules with integration tests (and therefore 2 tomcat instances embedded within spring boot apps) that the second module will fail to run even though it runs fine if the module is built by itself.

I have tracked the problem down to the org.apache.catalina.webresources.TomcatURLStreamHandlerFactory calling URL.setURLStreamHandlerFactory(..) for each spring boot app startup; all after the first call in the same JVM will fail with a "factory already defined" Error being thrown.

The workaround has been to clone and override the org.apache.catalina.webresources.TomcatURLStreamHandlerFactory private constructor so that it wraps the call to URL.setURLStreamHandlerFactory(..) in a try/catch which ignores the "factory already defined" Error.

I have created a sample multi-module maven build to demonstrate the issue:
spring-boot-tomcat-chain-issue.zip. Note that the README.txt explains how to apply the workaround which is off by default.

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