How to get Spring to use Tomcat server to test integration?

I use the default Tomcat built-in container. However, in some of my tests I use Wiremock (using Jetty below). This makes my integration tests work with the Jetty server, not with Tomcat.

Is there a way to get Spring to boot from Tomcat?

+4
source share
1 answer

As Stefan Nicholl said here , you must define emptyTomcatEmbeddedServletContainerFactory @Bean

Just adding such a bean was not enough for me. I got a "multiple exception beans". Since I was adding this to my own test starter, I just had to make sure it was added before resolution EmbeddedServletContainerAutoConfiguration, 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();
    }
}
+7
source

All Articles