What is the difference between ApplicationContext and WebApplicationContext in Spring MVC?

前端 未结 5 714
迷失自我
迷失自我 2020-11-22 06:53

What is the difference between Application Context and Web Application Context?

I am aware that WebApplicationContext is used for Spring MVC architectur

5条回答
  •  清酒与你
    2020-11-22 07:32

    ApplicationContext (Root Application Context) : Every Spring MVC web application has an applicationContext.xml file which is configured as the root of context configuration. Spring loads this file and creates an applicationContext for the entire application. This file is loaded by the ContextLoaderListener which is configured as a context param in web.xml file. And there will be only one applicationContext per web application.

    WebApplicationContext : WebApplicationContext is a web aware application context i.e. it has servlet context information. A single web application can have multiple WebApplicationContext and each Dispatcher servlet (which is the front controller of Spring MVC architecture) is associated with a WebApplicationContext. The webApplicationContext configuration file *-servlet.xml is specific to a DispatcherServlet. And since a web application can have more than one dispatcher servlet configured to serve multiple requests, there can be more than one webApplicationContext file per web application.

提交回复
热议问题