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

6 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[email protected]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

Manu S
Guest
I have followed the same steps but I am getting 404 error on the webpage. The last few logs from the server are as below. Seems like server is getting shutdown after the startup 2018-02-28 14:39:27.429 INFO 3440 — [localhost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-02-28 14:39:27.460 INFO 3440 — [localhost-startStop-1] c.m.medley.controller.Application : Started Application in 6.267 seconds (JVM running for 12.161) 2018-02-28 14:39:27.554 INFO 3440 — [localhost-startStop-1] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot[email protected]186b2a74: startup date [Wed Feb 28 14:39:22 PST 2018]; root of context hierarchy 2018-02-28 14:39:27.554 INFO 3440 — [localhost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on… Read more »
Gaurav
Guest

You have mentioned to add this dependency in pom.xml but this is already present inside spring-boot-starter-web, another thing is we need to exclude embedded tomcat then why do we need to add it ?

org.springframework.boot
spring-boot-starter-tomcat
provided

husseinterek
Guest

This dependency tells Spring Boot to not use its embedded tomcat, the keyword “Provided” does the full work.
If you remove this dependency, the application will use the embedded tomcat.