Deploy Spring Boot application on external Tomcat

Spring Boot provides an embedded servlet container which makes it very easy to setup and deploy web applications, by default all Spring Boot applications are exported as a runnable jar file and developers would only need to run this jar file on a java environment without the need to worry about installing and setting up servlet containers.

However, the embedded server may not be suitable for all production environments especially when the infrastructure is already set up and administrators need to have full control on the server, in this situation Spring Boot applications must run on external and separate servlet containers.

In this tutorial, we provide the required steps in order to deploy a Spring Boot web application on external Tomcat.

In order to understand what is Spring Boot and how do we create a Spring Boot web application, refer to “Introducing Spring Boot” tutorial.

Step #1

Add the following dependency to pom.xml in order to tell Spring Boot not to use its embedded Tomcat.

Step #2

Change the packaging property to war in pom.xml.

Step #3

Replace your initializer class with the following:

Then define it as a starting class in pom.xml:

Here is a full working pom.xml:

Step #4

Now that your Spring Boot application is ready to be deployed on external Tomcat, in order to export a war file from your application:

  • Right click pom.xml -> run-as -> Maven install
  • Maven generates a war file inside target folder

That’s it, for clarifications please leave your thoughts in the comments section below.

 

husseinterek

Founder of programmergate.com, I have a passion in software engineering and everything related to java environment.

You may also like...

Leave a Reply

2 Comments on "Deploy Spring Boot application on external Tomcat"

avatar
newest oldest most voted
Kesavan
Guest

After creating war file how to run this? in production server?

Gabriel Andrade
Guest

Im using spring boot with JSF and i am able to start the server just fine, but after a while(around 1 or 2 days), the server stops and cant startup again, giving me the error:
2018-02-18 10:30:08.018 INFO 7052 — [localhost-startStop-2] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2e601386: startup date [Thu Feb 15 13:20:57 UTC 2018]; root of context hierarchy
2018-02-18 10:30:08.033 INFO 7052 — [localhost-startStop-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown