How to Deploy Spring Boot Applications on External Tomcat Server

So far, in previous examples we used to deploy and run the applications using embedded tomcat server provided by the spring boot. Generally in the real-time projects we wont use inbuilt servers provided by the frameworks because of many reasons like security, maintenance and control. So in this article I will show you how can we deploy the spring boot applications on external servers (in this tutorial I am going to consider the external server as Tomcat).

Just do these changes to your spring boot application which you want to deploy it on to external tomcat server.

  • pom.xml, add dependency and packaging to war
  • Extend your main class with SpringBootServletInitializer and override its configure method
  • Generate WAR and deploy into the external server

If want you can change the context path also in the (Optional)


<!-- to export as WAR -->

<!-- packaging to WAR -->

Final pom.xml

    xmlns:xsi="" xsi:schemaLocation="">
    <!-- packaging to WAR -->
        <!-- Instruct spring boot not to use the inbuilt Tomcat server -->

Extend main Class with SpringBootServletInitializer


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

public class SpringBootApp extends SpringBootServletInitializer {

 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  return application.sources(SpringBootApp.class);

 public static void main(String[] args) {, args);



import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

public class SpringJava4sController {

 public String customerInformation() {
      return "Hey, I am from external tomcat";


Generate a WAR file

Right click on pom.xml -> Run as -> Maven install, this will generate a WAR file in your target folder.  Just copy that WAR file into your tomcat’s webapps folder and start the server ( or ) you can deploy and test from your IDE (eclipse/sts) by importing that WAR into your work space and run that in the external tomcat [I tried importing into eclipse].


If you observe the context path in the URL, its showing SpringBootAppInExternalTomcat-0.0.1-SNAPSHOT. Its not taking the context path we have given in the, rather its considering the context path as Artifact Id + Version from pom.xml. So if you want required context path, the only possibility is change pom.xml accordingly (if you know other ways please comment).

You can download the application and generate the WAR file with the above step and verify.


You Might Also Like

  ::. About the Author .::

- Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


2 Responses to “How to Deploy Spring Boot Applications on External Tomcat Server”
  1. Ajith Alex says:

    My students are referring to this tutorials. Good article dude. 🙂

  2. Hussain says:

    Nice explanation bro.


By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2018 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.