2

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?

MateuszPrzybyla
  • 897
  • 8
  • 17
  • 2
    By downgrading Spring Boot to the 1.5 branch. Spring Boot 2.0, requires a Servlet 3.1 container. Tomcat 7 is a Servlet 3.0 container. – M. Deinum Feb 27 '18 at 11:23
  • I would like to avoid it if possible - I'd prefer finding a solution for Spring Boot 2.0 since I would like to have a support for JUnit5. – MateuszPrzybyla Feb 27 '18 at 12:45
  • Spring Boot 2, requires Spring 5, which requires a Servlet 3.1 container. Your only option is to downgrade, if that is only for jUnit 5 there is also jUnit 5 support for Spring 4.3. See https://github.com/sbrannen/spring-test-junit5. Or upgrade to Tomcat 8.5 (which is the official 3.1 container). – M. Deinum Feb 27 '18 at 12:47
  • @M.Deinum - I downgraded the version to 1.5.10.RELEASE and now I have the embedded container in 7.0.82 version. But what's interesting is that I looked into the dependency versions that Spring Boot 1.5.10.RELEASE is using Servlet API also in 3.1.0 version. Any idea why it works for 1.5.10.RELEASE and not for 2.0.0.RC2 then? – MateuszPrzybyla Feb 27 '18 at 13:00
  • Because it isn't the minimal required version as that is Servlet 3.0 API. – M. Deinum Feb 27 '18 at 14:14
  • Any source? I don't see it anywhere in the docs. – MateuszPrzybyla Feb 28 '18 at 08:26
  • As stated it isn't in the Spring Boot docs it is in the Spring docs. – M. Deinum Feb 28 '18 at 08:27

1 Answers1

0

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

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

ssasi
  • 1,758
  • 1
  • 12
  • 18
  • Can you please share the reference to official document? – ssasi Mar 19 '19 at 10:44
  • 3
    Here's the official Spring Boot release notes on GitHub: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0.0-M1-Release-Notes#tomcat The link above can not be considered an official resource. – Victor Jun 04 '19 at 18:36