简体   繁体   English

Spring是独立的还是Tomcat?

[英]Spring as standalone or on Tomcat?

I am seeking for the advantages of having Spring deployed on Tomcat rather then have it out side of any application server container. 我正在寻找在Tomcat上部署Spring的优势,而不是将其放在任何应用程序服务器容器的一边。

My project doesn't require any web support. 我的项目不需要任何Web支持。 It does requires technologies like transactions management, DB pool, JMX, low latency and more common java-ee technology. 它确实需要诸如事务管理,数据库池,JMX,低延迟和更常见的java-ee技术等技术。

So why would I use tomcat anyway? 那么为什么我还会使用tomcat呢? if it's just because of the reason of having DB POOL, I could implement it myself. 如果只是因为有了PO POOL的原因,我可以自己实现它。 I am looking for low latency solution. 我正在寻找低延迟解决方案。

Again, my project is a total backend no need of any web support. 同样,我的项目是一个完整的后端,不需要任何Web支持。

So what do I miss here? 那我在这里想念什么?

What do you actually mean by "more common Java EE technology"? 您对“更常见的Java EE技术”的实际含义是什么?

If it's "just a back end", what is the front end? 如果它只是“后端”,那么前端是什么? How will applications talk to the back end? 应用程序如何与后端通信?

If there's no need for a web interface, there's no advantage to using a web container. 如果不需要Web界面,使用Web容器没有任何优势。

If you have complex transaction management needs, need message queues, etc. that may be easier to set up under an application server (as opposed to a web container) because there are existing admin/management interfaces. 如果您有复杂的事务管理需求,需要消息队列等,这可能更容易在应用程序服务器(而不是Web容器)下设置,因为存在管理/管理接口。 All those may also be set up on their own, but can be more of a pain--using Spring may mitigate that pain somewhat. 所有这些也可以单独设置,但可能更痛苦 - 使用Spring可以减轻这种痛苦。

The need for "more common Java EE technology", however, makes me a little nervous about implementing a standalone app, though. 然而,对“更常见的Java EE技术”的需求让我对实现独立应用程序感到有些紧张。 App containers have all that "common Java EE technology" built-in, tested, and functional. App容器具有内置,测试和功能的所有“通用Java EE技术”。 If you're bolting a variety of packages together to give you "common Java EE technology", without using a common Java EE app container, it's likely easier to just use an app container, which also gives you the benefit of providing normalized access to your services from a variety of sources. 如果您将各种软件包联系在一起为您提供“通用Java EE技术”,而不使用通用的Java EE应用程序容器,则可能更容易使用应用程序容器,这也为您提供了规范化访问权限的好处。您的服务来自各种渠道。

If your app is not a web app, you can use any of the non-web specific application contexts listed under All Known Implementing Classes here . 如果您的应用程序不是Web应用程序,则可以使用此处 所有已知实现类下列出的任何非Web特定应用程序上下文。 You can then init the context from a main method in a runnable jar. 然后,您可以从可运行jar中的main方法初始化上下文。

If you don't need web support, you don't have to use tomcat or any other app server. 如果您不需要Web支持,则不必使用tomcat或任何其他应用服务器。 Spring will provide you with most of the features you need. Spring将为您提供所需的大部分功能。 For connection pool, there are many options available such as c3p0 & apache dbcp. 对于连接池,有许多选项可用,例如c3p0和apache dbcp。 You can use one of them. 你可以使用其中一个。

The only thing you have to worry about is a clean shutdown of your process. 您唯一需要担心的是干净关闭您的流程。 You can do that by implementing your own shutdown hook. 您可以通过实现自己的关闭挂钩来实现。

One of the reasons to deploy the application in tomcat is that it will provide you all of the connection burden, thread management and so on. tomcat部署应用程序的原因之一是它将为您提供所有连接负担,线程管理等。 Nothing that you could not implement yourself. 没有什么是你自己无法实现的。 But bear in mind that tomcat is robust, and they already deal with all of the troubles of implement that logic. 但请记住, tomcat是健壮的,他们已经处理了逻辑实现的所有麻烦。

Besides of that there is little point in use an application container (if you think that not having to develop and maintain that amount of code is easy). 除此之外,使用应用程序容器几乎没有意义(如果您认为不必开发和维护大量代码很容易)。

You shouldn't use tomcat or anything else. 你不应该使用tomcat或其他任何东西。 Spring is container already. Spring已经是容器了。 Init spring in one simple thread, makes sure it has proper clean up flow. 初始弹簧在一个简单的螺纹中,确保它有适当的清理流程。 and that's all. 就这样。 I used to work on several server side integration application which do allot, communicate over different protocols to other server, and everything was easily done with out Web Containers or J2ee Application Servers. 我曾经在几个服务器端集成应用程序上工作,这些应用程序分配,通过不同协议与其他服务器进行通信,所有内容都可以通过Web Containers或J2ee Application Server轻松完成。 Spring have support for almost everything, sometimes with 3d party libs(caching, transactions, pools, etc ....) Simplified version could be like : Spring几乎支持所有内容,有时使用3d派对库(缓存,事务,池等等)。简化版本可以是:

...
pubcic static  void main (String args[]){
 Server.server = new Server(...);
 server.initSpringContext()
 server.keepAlive();
 server.cleanupResources();
}

..
abstract class Server{

abstract void initSpring();
abstract void cleanUpResources();
abstract void shutdown(){
  this.state = STOP;
};
public void keepAlive()
 while(state!=STOP){
  sleep(1000)
 }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM