Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 400
Alejandro Agapito Bautista Avatar asked Sep 21 '16 20:09

Alejandro Agapito Bautista


People also ask

What is the difference between an embedded container and a war?

Embedded container is used to execute executables jars. Embedded container is packed as dependency in executable jar and will be responsible for executing only single application. WAR approach on the other hand uses Application Server which might be used to execute multiple applications at the same time.

What is spring boot embedded container?

Spring Boot allows developers to easily build applications or services using the 3 most mature containers available: Tomcat, Undertow, and Jetty.

What is difference between spring boot jar and war?

JAR files allow us to package multiple files in order to use it as a library, plugin, or any kind of application. On the other hand, WAR files are used only for web applications.

Is spring boot embedded Tomcat production ready?

Spring Boot aims to be production ready, by default. This means that it ships with useful defaults out of the box that may be overriden, if necessary. By default, Spring Boot provides an embedded Apache Tomcat build.


2 Answers

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.

like image 63
Maciej Walkowiak Avatar answered Sep 19 '22 11:09

Maciej Walkowiak


About a month ago I had the question like yours. Let me share my conclusion:

1) JAR:

  • You can run independently every appliction with different ports (in linux, java -jar ... > app_logs.log &) and you can route it (e.g. nginx). Note that, restarting is not problem. You can write custom bash script (like this: ps aux | grep appname and kill by PID)
  • But there are some problems with configuring production app. Property files will archived into jar.

2) WAR

  • You can deploy into container and just run it. Easy managing at the server. If you want to re-configure app, open properties file from unarchived folder inside container, change it as need and restart container. So, managing and configuring will be easy.
  • But, if you want to run another app in this server with another port, then you must install another copy of container and config it.

So, in my practice, using war app easier than jar to manage and re-configure.

like image 20
Mirjalol Bahodirov Avatar answered Sep 23 '22 11:09

Mirjalol Bahodirov