How to deploy Spring Boot Web App War file to Tomcat Server with Maven build

The tutorial is a guide to traditional deployment problem: “How to create a Spring Boot Web App War file with Maven then deploys it on Tomcat server”


I. Technologies

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.6.RELEASE
– Tomcat: apache-tomcat-8.5.20

II. Practice

1. Create a War file

– Create Spring Boot Web App
extends SpringBootServletInitializer & override configure method
– Update build configuration: war
– Configure embedded servlet container dependency as provided

1.1. Create Spring Boot Web App

– Open Spring Tool Suite, on main menu, choose File->New->Spring Starter Project, add project info, then press Next for needed dependencies:
For Template Engines, choose Thymeleaf
For Web MVC, choose Web->Web

Spring Boot Web App War file

Open pom.xml file to check dependencies:

– Create a simple controller WebController

– Create a simple view page: home.html

1.2. Extends SpringBootServletInitializer

In main class, extends SpringBootServletInitializer subclass and override configure method. Details:

1.3. Update build configuration

– Update your build configuration: war
– Configure embedded servlet container dependency as provided

2. Deploy War file on Tomcat

– Build the project: maven clean install. Then go to target folder, we have a war file: SpringBootWarDeployment-0.0.1.war.

– Copy SpringBootWarDeployment-0.0.1.war to apache-tomcat-8.5.13\webapps folder and rename it to javasampleapp.

– Go to apache-tomcat-8.5.13\bin, then start: startup.bat(startup.sh)

Results:

Spring Boot Web App War file result

III. SourceCode

SpringBootWarDeployment

By JavaSampleApproach | April 11, 2017.

Last updated on August 10, 2017.


Related Posts


3 thoughts on “How to deploy Spring Boot Web App War file to Tomcat Server with Maven build”

  1. Hi JavaSampleApproach,

    I have implemented spring boot microservice application using Eureka with zuul.

    When I deploy these microservices as war files into external tomcat server, zuul routing is not working properly.

    1. How to deploy spring boot microservice application into the old container(tomcat)?
    2. I have some services like Eureka server, gateway (zuul routing), etc.
    3. How to deploy all services (except gateway and Eureka) in single external tomcat (old container style)?

    Regards,
    Srinivas.

Got Something To Say:

Your email address will not be published. Required fields are marked *

*