'How to force Spring Boot to use Tomcat server in integration tests?
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 1:[1]
With Spring Boot 2.3 the above solution hasn't worked for me.
Perhaps I have special circumstances with not having a SpringBootApplication in the main classes. I have only a SpringBootApplication in the test classes.
Anyhow this has worked for me:
@SpringBootApplication(exclude = org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration.class)
public class TestApplication {
}
Solution 2:[2]
with Spring Boot 2.5.10
@AutoConfigureBefore(ServletWebServerFactoryAutoConfiguration.class)
didn't work for me.
but as sven doring mentioned excluding EmbeddedWebServerFactoryCustomizerAutoConfiguration worked for me.
it even worked for external tomcat
code is below
@SpringBootApplication(exclude = org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration.class)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sven Döring |
| Solution 2 |
