You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.