Actually, Spring Boot comes with support for embedded container support. One of them is for sure Tomcat. The default value for org.springframework.boot:spring-boot-starter-web .
With org.springframework.boot:spring-boot-starter-test and its @SpringApplicationConfiguration and @WebIntegrationTest you can achieve your requirements even with a random port .
See the Spring Boot reference guide for more information:
To change the port, you can add environment properties to @WebIntegrationTest as name and value pairs, separated by a colon or equal, for example. @WebIntegrationTest ("server.port: 9000"). In addition, you can set the server.port and management.port properties to 0 to run your integration tests using random ports.
In this case, your @SpringBootApplicaiton will be deployed for the built-in Tomcat, and your test can access the running services / controllers.
Note: it doesnβt matter if your Spring Boot application has Spring integration tools. The behavior is the same: built-in servlet tests and integration with @Value("${local.server.port}") .
source share