Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 230
Grzegorz Poznachowski Avatar asked Mar 07 '16 13:03

Grzegorz Poznachowski


People also ask

Can we override Tomcat server in spring boot?

The Spring Boot framework provides the default embedded server (Tomcat) to run the Spring Boot application. It runs on port 8080. It is possible to change the port in Spring Boot.

How do I change the default Tomcat in spring boot?

Another way to change the port of embedded tomcat in the Spring Boot application is by specifying the server. port property in the resource file. For example, if you want your Spring boot application to listen on port 8080, then you can specify server. port=8080 on the application.


1 Answers

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 {
}
like image 85
Sven Döring Avatar answered Oct 16 '22 07:10

Sven Döring