Issue
I use default Tomcat embedded container. However, in some of my tests I use Wiremock (using Jetty underneath). This makes my integration tests run against Jetty server, not Tomcat.
Is there any way to force Spring Boot to stick with Tomcat ?
Solution
As Stéphane Nicoll stated here you should define an empty TomcatEmbeddedServletContainerFactory
@Bean
Simply adding such bean was not sufficient for me. I got 'multiple beans' exception. As I was adding that to a custom test starter I just had to make sure, it is added before EmbeddedServletContainerAutoConfiguration
resolution took place, i.e:
@Configuration
@AutoConfigureBefore(EmbeddedServletContainerAutoConfiguration.class)
public class ForceTomcatAutoConfiguration {
@Bean
TomcatEmbeddedServletContainerFactory tomcat() {
return new TomcatEmbeddedServletContainerFactory();
}
}
Edit: In Spring Boot 2.0 this works for me:
@Configuration
@AutoConfigureBefore(ServletWebServerFactoryAutoConfiguration.class)
public class ForceTomcatAutoConfiguration {
@Bean
TomcatServletWebServerFactory tomcat() {
return new TomcatServletWebServerFactory();
}
}
Answered By - Grzegorz Poznachowski
Answer Checked By - Marie Seifert (JavaFixing Admin)