Using Spring Boot 2.0 with Tomcat 7.0.82

MateuszPrzybyla picture MateuszPrzybyla · Feb 27, 2018 · Viewed 7.1k times · Source

I have a project that uses Spring Boot 2.0.0.RC2. I need to deploy it to a customer environment using traditional deployment for Tomcat 7.0.82. I've managed to build a war that can be deployed successfully by configuring web.xml in a typical way for Spring applications (with DispatcherServlet) instead of using SpringBootServletInitializer.

I also would like to have a quick way of starting the app on local environment using an embedded Tomcat container by simply running the main method in the application class with @SpringBootApplication annotation. It works fine if I'm using the default Tomcat version (8.5.28). However, I would like to start the embedded container also in 7.0.82 version. This is important for me for another reason - I'm using SpringBootTest and it would be nice if those tests run on the exact same container as the customer environment. Unfortunately, I can't use the Spring Boot parent POM and override tomcat.version property.

I've tried @SpringBootApplication(exclude = ServletWebServerFactoryAutoConfiguration.class) create TomcatServletWebServerFactory bean manually

@Bean
public ServletWebServerFactory tomcatServletWebServerFactory() {
    return new TomcatServletWebServerFactory();
}

and add tomcat 7.0.82 dependencies explicitly in pom.xml (${tomcat.version} = 7.0.82):

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-annotations-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-el</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-websocket</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-annotations-api</artifactId>
    <version>${tomcat.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-util</artifactId>
    <version>${tomcat.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-core</artifactId>
    <version>${tomcat.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-el</artifactId>
    <version>${tomcat.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-websocket</artifactId>
    <version>${tomcat.version}</version>
</dependency>

but I'm still getting a java.lang.NoClassDefFoundError: org/apache/tomcat/util/scan/StandardJarScanFilter error.

Could you please advise if there is any way to meet my requirements?

Answer

Lucas Moyano Angelini picture Lucas Moyano Angelini · Sep 11, 2018

Spring boot 2: The minimum supported version of Tomcat is 8.5

Reference: https://dzone.com/articles/spring-boot-20-new-features-infrastructure-changes