0

I want to deploy WAR file, created from Spring Boot project, in Tomcat 7. I followed instructions from official Spring page link. If i understood correctly there are 3 steps to be done in order to create WAR file successfully:

  1. Extend main class with SpringBootServletInitializer and override configure method
  2. In pom.xml set packaging to 'war'
  3. In pom.xml mark the embedded servlet container dependency as provided.

After i did all these steps i created WAR file successfully and deployed it to Tomcat 7(localhost), anyhow my controller is not reachable, HTTP Status 404. If i run it with embedded settings i am able to reach controller method.

In addition please see bellow my 'Main' class and pom.xml.

Main class:

@ComponentScan(basePackages="com.sekulicd")
@EnableWebMvc
@Import(DatabaseConfig.class)
@SpringBootApplication
public class RunApplication extends SpringBootServletInitializer 
{
@Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(RunApplication.class);
    }

    public static void main(String[] args)
    {
        SpringApplication.run(RunApplication.class, args);
    }
}

pom.xml:

<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.sekulicd</groupId>
<artifactId>SpringBoot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.7.RELEASE</version>
</parent>

<properties>
    <start-class>com.sekulicd.boot.RunApplication.java</start-class>
</properties>

<dependencies>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>3.0</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-couchbase</artifactId>
    </dependency>


</dependencies>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>http://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

<build>
    <finalName>Test</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <jvmArguments>
                    -Xdebug
                    -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
                </jvmArguments>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

If anybody have an idea if i missed something or did something wrong please advise.

Jens
  • 67,715
  • 15
  • 98
  • 113
sekula87
  • 347
  • 1
  • 7
  • 19
  • 1
    Is the path different when you run in embedded controller and on tomcat server? on tomcat it should be `tomcatserver:port/wardirectory/controllermapping` unless you configured otherwise. – jny Nov 13 '15 at 14:38
  • Yes that was the issue, strange thing is that when i deploy it to localhost link is opening however if war is deployed in AWS again i am getting 404, any idea why? – sekula87 Nov 13 '15 at 17:37
  • Did you find a solution for this I'm facing similar issue – astra03 Jul 21 '16 at 20:30
  • Check this answer: https://stackoverflow.com/questions/38789477/spring-boot-war-not-working-in-tomcat-7-but-working-in-tomcat-8/47394884#47394884 – kinjelom Nov 20 '17 at 14:59

1 Answers1

0

Besides the above steps, it's worth checking the following equally important points:

  1. JRE/JDK version of underlined Application server(Tomcat, JBoss) compared to mentioned in POM.xml. Better to remove this tag from xml.

  2. Check maven plugins version mentioned in POM.xml in plugin section.

  3. Try deploying expanded WAR/JAR(Meta & Web INFs) folders instead of archive, in case server is not expanding placed WAR implicitly.

  4. Check scope of packages classes with use of @Componentscan().

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Nikhil
  • 1
  • 1