java servlet 容器和 spring 容器有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28040529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:54:40  来源:igfitidea点击:

what is the difference between servlet container and spring container?

javaspringservlets

提问by Balasubramani

What are the roles and responsibility of servlet container and spring container? Please someone clarify my doubts.

servlet容器和spring容器的作用和职责是什么?请有人澄清我的疑问。

回答by davioooh

They are very different concepts also if their names are similar.

如果它们的名称相似,它们也是非常不同的概念。

A Servlet Containeror Web Container (like Tomcat) is an implementation of various Java EE specifications like Java Servlet, JSP, etc. Put in a simple way, it is an environment where Java web applications can live. A web server + Java support.

一个Servlet容器或Web容器(如Tomcat的)是各种Java EE规范一样的Java Servlet,JSP等以简单的方式把的实现,这就是Java的Web应用程序可以生活的环境。Web 服务器 + Java 支持。

A Spring Containeron the other hand, is the core and the engine of the Spring Framework. It is an IoC Containerthat handles Spring applications lifecycle creating new beans and injecting dependencies.

一个Spring容器,另一方面,是核心和Spring框架的引擎。它是一个IoC 容器,用于处理 Spring 应用程序生命周期、创建新 bean 和注入依赖项。

Because a Spring application can be a web application, a Spring Container can "live" inside a Web Container.

由于 Spring 应用程序可以是 Web 应用程序,因此 Spring Container 可以“存在于”Web Container 中。

For further information:

了解更多信息:

回答by SMA

Spring container is responsible for creating the objects, wiring them together, configuring them, and managing their complete lifecycle from creation till destruction. The Spring container uses dependency injection (DI) to manage the components that make up an application. These objects are called Spring Beans.

Spring 容器负责创建对象,将它们连接在一起,配置它们,并管理它们从创建到销毁的完整生命周期。Spring 容器使用依赖注入 (DI) 来管理组成应用程序的组件。这些对象称为 Spring Bean。

While Servlet container is basically web server or application server one who is responsible for creating and maintaining life cycle of a servlet like init, service, destroy in a nut shell. It has other functionalities as well in addition to maintaining lifecycle of a servlet.

虽然 Servlet 容器基本上是 Web 服务器或应用程序服务器,负责创建和维护 servlet 的生命周期,如 init、service、destroy。除了维护 servlet 的生命周期外,它还具有其他功能。