Is embedded Tomcat a good choice for deployment to production [closed]
Asked Answered
G

1

11

Conventionally, a Servlet Maven project is deployed to Tomcat production server by deploying a generated war to the - webapps - directory of Tomcat. However, Spring-Boot, as a practical trend, recommends jar over war. This preference has no problem for testing, but in case of deployment to an existing Tomcat server in Production, AFAIK, only a war is accepted. So my solution would be:

  1. Generate a corresponding war by modifying the Maven's pom.xml, i.e. set the value of packaging element as war as such: <packaging>war</packaging>. But this is manifestly an extra step
  2. Deploy the project in Production as a running Java program with the embedded Tomcat, meaning there is no normal Tomcat Server at all in production. But is the embedded Tomcat as stable in production as the normal Tomcat server?
  3. In case of deploying a Spring MVC project (no Spring Boot!) to an existing Tomcat server, I tried to use Tomcat Maven plugin in the testing phase instead of using Eclipse with Tomcat server configuration as the Tomcat server should be installed locally as a prerequisite.

Question: Are the solutions above OK? or are there any other better solutions of deployment to production? In case of the third solution, there is only Tomcat7 Maven plugin according to my knowledge, what if I only want to test with Tomcat 8 or Tomcat 9? I tried to use a main class to start up an embedded Tomcat, but it is superb difficult to deal with the dependencies.

Gelignite answered 18/3, 2017 at 22:0 Comment(9)
If you dont need any other webapps running on that server, I dont see why running embedded tomcat should be problematic provided you do some kind of stability testingAlgoid
@MasterAzazel Thanks for your comment :) but what about just in case of multipe webapps in the Tomcat server? What solution would be agile? My first solutions seems not to be handyGelignite
This is much a preference / determination based on your environment. This might have some good info to read. spring.io/blog/2014/03/07/deploying-spring-boot-applicationsGuernsey
The most popular (hipster) approach these days is to have a separate docker container (or a group of docker containers) per app. Each docker container running an embedded webserver (Tomcat) with your app.Complimentary
@Rui, why you are coming out of conventional way? Why you need spring boot? Ask these questions to yourself. FYI - we deployed more than 3 webapps which are running successfully in PROD for ~2 years, one app deployed like your option1 and another like your option2. No Worries :-)Cranberry
I am noticing Agile mentioned. Depends what you mean. Where I work, we commit code, and it's built through CI/CD and automatically deployed to CloudFoundry/AWS (if tests pass during the build process).Guernsey
@SundararajGovindasamy I tried Spring Boot for fun, and really enjoyed its convenience, so if I am required to do a web Servlet project for the outset, I definitely will choose Spring Boot over pure Spring mvc. According to your experience, my option 2 seems to be viable. Thanks for telling this :) But for option one, I really don't feel like it :) I really long for something smarterGelignite
@AdamSiemion You gave a really really valuable suggestion. This is what I am seeking for :) Thumb up <3Gelignite
@Guernsey Thanks first for your link :) I appreciate it and definitely will and have to read it through. btw, the "agile" I meant is that in the aspect of software engineering, it is reasonable to make the testing and deployment as simple as possible, with as few steps as possibleGelignite
V
1

I think yes for cloud environment that manages replicas for you as docker containers.

If you deploy as WAR then for the sake of HA you should run multiple aplication server nodes and thus embedded tomcat is not needed.

At the end, it matters the most on how your environment looks right now. With embedded server you loose some features of separate server instances but if you plan to use something like AWS for automatic tasks then it should suffice.

Overall, I think embedded should be ok. You are right that there is a term

make JAR, not WAR

but only drawback of WAR is that using spring boot you cannot use reactive programming I think. Packaging does not matter in your case. It matters in cloud environment because you ensure HA using replicas and for the best as docker containers.

Videlicet answered 30/6, 2022 at 9:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.