内置Tomcat还是外部Tomcat?

1. 来自 www.quora.com 的答案

原文: https://www.quora.com/Is-it-better-to-run-a-Spring-Boot-application-in-an-external-Tomcat-compared-to-internal

Is it better to run a Spring Boot application in an external Tomcat compared to internal?
Ad by DigitalOcean
Deploy a Tomcat server on DigitalOcean - free $100/60-day credit.
Get started for $5/mo with 1vCPU, 1GB RAM and 25GB SSD with free monitoring and alerting.
Learn more at try.digitalocean.com
1 Answer
Marco Behler
Marco Behler, Programmer; Author; Java Screencaster @ www.marcobehler.com
Answered Oct 30 2017 · Author has 227 answers and 39.4k answer views
I think you are probably talking about the embedded tomcat vs external tomcat. Funnily enough, both tomcats are pretty much the same, i.e. the same sources etc.

The only difference (apart from religious beliefs 😉 ) is, that you should choose whatever fits best into your current company IT infrastructure. If you deploy 100% of your applications as .war files, it is quite a political and technical feat to migrate everything to fat jars or run only embedded fat jars in the future.

179 Views · View Upvoters

2. 来自 https://stackoverflow.com 的答案

原文:https://stackoverflow.com/questions/39626267/spring-boot-embedded-container-or-war-file-in-an-external-container-for-producti?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

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:

If i want to set it as a windows or linux service, is the jar file the best option?
If i use the jar file I’m not going to have access to restart the server.
Maybe in the future I need more applications in the same container.
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.

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.

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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值