Configure multiple servletcontainers/servlets with spring boot

ghz 1years ago ⋅ 7268 views

Question

I want to load two servlet containers with embedded tomcat configuration on different ports with Spring Boot.

Does anyone know how to achieve this?


Answer

It should be simple: just create as many ApplicationContexts of type EmbeddedWebApplicationContext as you need and give them each an EmbeddedServletContainerFactory with a different port. Example [here](https://github.com/spring-projects/spring- boot/blob/af75dd0e4090db706afe4a7bd40d226b413e01a0/spring-boot- actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java#L158) where the two contexts are parent and child, but that's not a necessary part of the setup.