0

I'm trying to get Spring Boot + WAR working in our test environment. The test environment has Tomcat 7 installed and when deploying I get the following errors:

Aug 05, 2016 2:33:19 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/var/lib/tomcat7/webapps/prt/WEB-INF/lib/tomcat-embed-core-8.0.33.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Aug 05, 2016 2:33:19 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/var/lib/tomcat7/webapps/prt/WEB-INF/lib/tomcat-embed-el-8.0.33.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class

Now the weird thing is that this same WAR is working on my local Tomcat 8. Does anyone have any idea why my Tomcat 7 instance does not accept the WAR? I have already tried excluding tomcat in the pom.xml and I am using the method configure() in SpringBootServletInitializer.

Jelle den Burger
  • 1,428
  • 17
  • 31

2 Answers2

1

Check the following configuration:

pom.xml

<properties>
    <tomcat.version>7.0.78</tomcat.version>
    <servlet-api.version>3.0.1</servlet-api.version>
</properties>

<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${servlet-api.version}</version>
        <scope>provided</scope>  <!-- provided: tomcat/lib/servlet-api.jar -->
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-juli</artifactId>
        <version>${tomcat.version}</version>
        <scope>runtime</scope> <!-- runtime: tomcat/bin/tomcat-juli.jar -->
    </dependency>
    <!-- remove it:
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    -->
</dependencies>

Traditional deployment

To create a deployable war file (Tomcat 7) read this guide: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

  • <packaging>war</packaging>
  • override: SpringBootServletInitializer.configure:

    @SpringBootApplication
    public class Application extends SpringBootServletInitializer {
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
        public static void main(String[] args) throws Exception {
            SpringApplication.run(Application.class, args);
        }
    }
    
kinjelom
  • 6,105
  • 3
  • 35
  • 61
-1

solution 1.using outside tomcat(you can not use embed tomcat)

  <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-web</artifactid>
            <exclusions>
                <exclusion>
                    <groupid>org.springframework.boot</groupid>
                    <artifactid>spring-boot-starter-tomcat</artifactid>
                </exclusion>
            </exclusions>
     </dependency>

solution 2. setting tomcat version

   <properties>
            <tomcat.version>7.0.59</tomcat.version>
     </properties>
  • 1
    Can you perhaps expand a little bit more on your answer? While the section above may be useful for someone who knows exactly what they're doing, for other people it may be hard without any frame of reference. – roelofs Nov 21 '17 at 04:15