Using Spring Boot 2.0 with Tomcat 7.0.82

吃可爱长大的小学妹 提交于 2019-12-10 22:37:40

问题


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?


回答1:


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

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



来源:https://stackoverflow.com/questions/49007157/using-spring-boot-2-0-with-tomcat-7-0-82

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!