简体   繁体   English

Spring Web应用程序体系结构中的上下文级别

[英]Context Level in Spring Web Application Architecture

I am struggling with Architecture level of Spring web application, Below I am making my pointers. 我正在为Spring Web应用程序的体系结构级别而苦苦挣扎,下面我将指出自己的观点。 Please help regarding the below: 请在以下方面提供帮助:

Context Level Programing: Servlet Context and Root Application Webapplication context and Web Application context. 上下文级别编程: Servlet上下文和根应用程序Web应用程序上下文和Web应用程序上下文。

  1. I don't know which bean needs to mention on which level. 我不知道哪个豆需要在哪个级别上提及。

  2. What is the Hierarchy level of Context in Spring Web Application. Spring Web Application中的上下文层次结构级别是什么。 which comes upper or lower. 最高或最低。

  3. Which context is under which context. 哪个上下文在哪个上下文下。

My Understanding is Servlet Context is the object of Servlet Container (tomcat container), and Servlet container is responsible to manage all the servlet, where all servlet lives. 我的理解是Servlet上下文Servlet容器 (tomcat容器)的对象,并且Servlet容器负责管理所有servlet所在的所有servlet。

All Bean dependecies Lives in Application container, and root web application context is the object of Application Container. 所有Bean依赖项都驻留在Application容器中,而根Web应用程序上下文是Application Container的对象。

Every servlet have its own web application context, i don't know what is this, is it same as Servlet context. 每个Servlet都有自己的Web应用程序上下文,我不知道这是什么,它与Servlet上下文相同。

4. And Relation between them? 4.他们之间的关系?

Please describe it with help of diagram like this, (It will be really appreciable) 请在这样的图表的帮助下进行描述,(非常感谢)

This is just example to understand which loads first and what is inside what. 这仅是了解哪个首先加载以及什么内部加载的示例。 Please check this reference diagram 请检查此参考图

Think of context as a component's execution environment. 将上下文视为组件的执行环境。

A servlet container (Web server), hosts web applications and on startup it creates one ServletContext for each of these applications. 一个Servlet容器(Web服务器)承载Web应用程序,并在启动时为每个这些应用程序创建一个ServletContext。 So each web app lives in a servlet context which provides to it information about its environment (container). 因此,每个Web应用程序都位于一个Servlet上下文中,该上下文为其提供有关其环境(容器)的信息。 This is Java Servlet API. 这是Java Servlet API。 Tomcat is an implementation of this API. Tomcat是此API的实现。

Now, Spring is one of the frameworks we can use to create web apps. 现在,Spring是我们可以用来创建Web应用程序的框架之一。 When we deploy our web app in the container, it (container) will create a ServletContext and this is where our app will live in. 当我们在容器中部署Web应用程序时,它(容器)将创建一个ServletContext,这就是我们的应用程序所在的位置。

Each Spring application has a root context (ApplicationContext) and in it one or more child contexts can exist. 每个Spring应用程序都有一个根上下文(ApplicationContext),并且可以在其中存在一个或多个子上下文。 WebApplicationContext extends ApplicationContext. WebApplicationContext扩展了ApplicationContext。 There can be many WebApplicationContexts, children of the root context of an application. 可以有许多WebApplicationContexts,它们是应用程序根上下文的子级。 The WebApplicationContext (which adds a method, getServletContext() ) is able to work with the ServletContext in which it lives. WebApplicationContext(添加了方法getServletContext())能够与它所在的ServletContext一起使用。

So in a spring based web app deployed in a container: 因此,在部署在容器中的基于Spring的Web应用程序中:

container --contains 1..n--> ServletContext --contains 1--> ApplicationContext --contains 1..n--> WebApplicationContext 容器-包含1..n-> ServletContext-包含1-> ApplicationContext-包含1..n-> WebApplicationContext

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

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