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...

13
Leave a Reply

avatar
9 Comment threads
4 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
10 Comment authors
prasanna胡永青pandirajanpradeSanjeev Kumar Recent comment authors
newest oldest most voted
Kesavan
Guest
Kesavan

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

Gabriel Andrade
Guest
Gabriel Andrade

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
Manu S

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
Gaurav

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
husseinterek

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.

Sanjeev Kumar
Guest
Sanjeev Kumar

Thanks dear . I used your guide line to run a spring boot based application within STS on external tomcat server which is not an embeded server of STS.

Sanjeev Kumar
Guest
Sanjeev Kumar

But when the code is built with junit test generated , it doesnt compile. But when I delete it , it compiles well and after running it a login page gets opened. But this login page is no where within the application. From where is it coming? Please share your understanding as to this login page and why it is not compiled with test case?

prade
Guest
prade

java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.cata
lina.LifecycleException: Failed to start component [StandardEngine[Catalina].Sta
ndardHost[localhost].StandardContext[/sm_Crawl_w-0.0.1-springboot app]]

getting this error, please give solution

胡永青
Guest
胡永青

我也是这个错误,但不知道怎么解决

胡永青
Guest
胡永青

I found my mistake, I don’t know if it is useful to you!Large packages are put into the server side database without changing!

pandirajan
Guest
pandirajan

I done every this as you mentioned this tutorial. my tomcat server ran successfully but I didn’t get home page after this I seen my server it didn’t show any error but I am facing this problem.

prasanna
Guest
prasanna

i am new in spring and i follow the step but after deploy war file i got the exception
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘serverProperties’ defined in class path resource [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException

27-Jul-2018 15:19:50.731 SEVERE [main] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [D:\servers\goa_server\webapps\SpringBootStandAloneWarExample-1.0.0.war] java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SpringBootStandAloneWarExample-1.0.0]]