Java – Spring boot embedded container or war file in an external container for production

javamavenspringspring-boottomcat

I'm complete able to configure spring boot in both cases, the question here is which of them are more robust and is the more recommended, because I didn't find in the spring boot documentation the recommended way to deploy it in a production environment, my concerns about use the embedded container are:

  1. If I want to set it as a Windows or Linux service, is the jar file the best option?
  2. If I use the jar file I'm not going to have access to restart the server.
  3. Maybe in the future I need more applications in the same container.
  4. If I restart the machine I have to execute again the java -jar.

The question in general is which is better use the jar file and execute it as java -jar jarname.jar in production or change the packaging to war set the tomcat as provided and set the generated war in an empty tomcat.

I hope you can help me.

—EDIT—

Many times the answer is depends, this is for a normal web application or REST web service.

Best Answer

jar packaging is perfectly suitable for production and you should rather fallback to war only if you really have to - which is often the case when you cannot control your deployment environment (which is often the case in large enterprises).

There is a chapter in Spring Boot Reference about setting up Spring Boot based application as a Unix/Linux/Windows service: Installing Spring Boot applications.

Regarding your concern:

Maybe in the future I need more applications in the same container.

With embedded containers if you need more applications running on the same machine, you should start two applications separately, each running on different port and effectively you will end up with two containers running - which is good, applications are better isolated from each other.