Spring boot app vs .war file deployed on Tomcat/Jetty

ilovkatie :

In my case let's consider a simple RESTful service created and configured with Spring Boot. This service communicates with a database (e.g. Postgres).

What is a difference between:

  • Building a Spring Boot .jar file and run it on my remote public host via java -jar myservice.jar?

or

  • Package it to .war file and deploy it on Tomcat/Jetty?

First option seems to be a lot easier, u just need to run a .jar. In second option u need to create Tomcat instance, run it and then deploy a .war file. Is there any other difference? Any pros and cons of both method?

so-random-dude :

Package it to .war file and deploy it on Tomcat/Jetty?

Don't do this if at all possible. Reason: with embedded tomcat (or any other server runtime like undertow, netty, jetty etc) it's much easier to build a micro-services architecture.

As Josh Long once said in one of his Spring IO talks “make Jar, not War”

On the other hand, if you have an existing infrastructure out there with servlet containers and already there are multiple application.wars running in those servlet containers, and all you have to do is just package your application as a war file and hand it over to a release team (or rather you are forced to just reuse the existing infrastructure), then it's a different story...But, tech-world is already moving away from this practice.

Again, in the spirit of microservices, in the spirit of what spring boot intended for, I would encourage you to use embedded server and make runnable jar file rather than going with traditional deployment.

Edit

If you are dockerizing your application, you have 2 options to package your tomcat in your "final artifact" (by "final artifact", I meant docker image, not the jar. Jar is just an intermediate artifact here).

  1. Use embedded tomcat so that tomcat will be packed in your jar and use a JVM docker image

OR

  1. Exclude tomcat from your jar and just pack your application and use a tomcat Docker image.

Still, any day, I would go with 1st option because that make development process much easier (and this goes with out saying, on-boarding a new developer will be easier).

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=447825&siteId=1