Getting issue while deploying spring boot war on tomcat 7

11,059

Solution 1

It seems you build yourself a war file. You should use spring to do that.

I have full example here https://www.surasint.com/spring-boot-create-war-for-tomcat/

pom.xml should look like this

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
    </parent>

    <groupId>com.surasint.example</groupId>
    <artifactId>spring-boot-12</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- JSP -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- to deploy as a war in tomcat -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- jstl for jsp -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

The key point are:

<packaging>war</packaging>

and:

<!-- to deploy as a war in tomcat -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

Solution 2

Your project references the class org.springframework.web.filter.FormContentFilter which resides in spring-web artifact since version 5.1.

So you'll either need to remove the reference to that class or add the missing spring-web artifact.

Share:
11,059

Related videos on Youtube

radhika garg
Author by

radhika garg

Updated on June 04, 2022

Comments

  • radhika garg
    radhika garg about 2 years

    I am having issue in deploying my code on the tomcat server I have written the below code.

    My main class:

    package com.indiamart.search;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
    
    @SpringBootApplication
    public class SuggestMcatApplication  extends SpringBootServletInitializer{
    
        public static void main(String[] args) {
            SpringApplication.run(SuggestMcatApplication.class, args);
        }
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
            // TODO Auto-generated method stub
            return builder.sources(SuggestMcatApplication.class);
        }}
    

    My controller class :-

    package com.abc.search;
    import java.util.HashMap;
    import java.util.Map;
    import javax.servlet.http.HttpServletRequest;
    
    import org.json.JSONObject;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;
    
    
    @RestController
    public class serviceController {
    
        @RequestMapping("/suggestMcat/related_info")
    
        public String getSearchString(HttpServletRequest request){
            JSONObject json;
            json =  new JSONObject(request);
            return json.toString();
        }
        }
    

    My pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.abc</groupId>
    <artifactId>suggestMcat</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>suggestMcat</name>
    <description>Demo project for Spring Boot</description>
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    </properties>
    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.json/json -->
    <dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20171018</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/net.sf.jazzy/jazzy -->
    <dependency>
    <groupId>net.sf.jazzy</groupId>
    <artifactId>jazzy</artifactId>
    <version>0.5.2-rtext-1.4.1</version>
    </dependency>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    </dependency>
    </dependencies>
    <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.0</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
    </plugin>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <outputDirectory>../../tomcat/webapps/</outputDirectory>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <warName>${project.artifactId}</warName>
    </configuration>
    </plugin>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <executions>
        <execution>
            <id>install-javaml-jar</id>
            <phase>clean</phase>
            <configuration>
                <file>${project.basedir}/src/main/resources/javaml-0.1.6.jar</file>
                <repositoryLayout>default</repositoryLayout>
                <groupId>com.indiamart</groupId>
                <artifactId>javaml</artifactId>
                <version>0.1.6</version>
                <packaging>jar</packaging>
                <generatePom>true</generatePom>
            </configuration>
            <goals>
                <goal>install-file</goal>
            </goals>
        </execution>
        <execution>
            <id>install-ajt-jar</id>
            <phase>clean</phase>
            <configuration>
                <file>${project.basedir}/src/main/resources/ajt-2.11.jar</file>
                <repositoryLayout>default</repositoryLayout>
                <groupId>com.indiamart</groupId>
                <artifactId>ajt</artifactId>
                <version>2.11</version>
                <packaging>jar</packaging>
                <generatePom>true</generatePom>
            </configuration>
            <goals>
                <goal>install-file</goal>
            </goals>
        </execution>
    </executions>
    </plugin>   
    </plugins>
    <finalName>${project.artifactId}</finalName>
    </build>
    </project>
    

    I m getting the below error when i m building the war and deploying on tomcat server:

    Caused by: java.lang.NoClassDefFoundError: org/springframework/web/filter/FormContentFilter
                at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
                at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1009)
    2018-12-04 17:59:39.859  WARN 14727 --- [io-8080-exec-29] o.s.boot.SpringApplication               : Unable to close
         ApplicationContext
    
             java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration]
         from ClassLoader [WebappClassLoader
               context: /suggestMcat
               delegate: false
               repositories:
                 /WEB-INF/classes/
             ---------- Parent Classloader:
             java.net.URLClassLoader@3dd4520b
    

    Please suggest.

    After the answer 2 my issue has been resolved of deploying but the issue is coming with controller Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

    Tue Dec 04 21:36:49 IST 2018 There was an unexpected error (type=Not Found, status=404). No message available

    • Gimby
      Gimby over 5 years
      Just to note: the spring boot 2 minimum supported version of Tomcat is 8.5.
  • radhika garg
    radhika garg over 5 years
    But now issue is coming with routing request: i m using the below parameter localhost:8080/suggestMcat/… and issue is coming as Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Tue Dec 04 21:36:49 IST 2018 There was an unexpected error (type=Not Found, status=404). No message available
  • radhika garg
    radhika garg over 5 years
    I had added the controller file in the question posted. Please check it once.
  • radhika garg
    radhika garg over 5 years
    Also.. I m getting the below error org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/Validatio‌​nAutoConfiguration.c‌​lass]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.validation.beanvalidation.LocalValidato‌​rFactoryBean]: Factory method 'defaultValidator' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/el/ELManager
  • Surasin Tancharoen
    Surasin Tancharoen over 5 years
    @radhikagarg I suggest you to look in the examples in my website there. Start one by one. And as someone commented, you should use tomcat 8.5. That would help alot.