spring context的层次关系

一、ServletContext

Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.

全局的context,包含springcontext、dispatchservlet、filter、lisener等;

在tomcat扫描应用时创建。

 

二、spring context

WebApplicationContext

包含spring中配置的运行所需的所有全局环境变量。

contextLoaderListener时创建。

 

三、dispatch context

包含处理事务所需的环境变量。

被dispatcherservlet所持有,引用spring context以查找全局的环境变量。

 

applicationContext AnnotationConfigServletWebServerApplicationContext  (id=95)

 

FrameworkServlet

 

@Override

public void setApplicationContext(ApplicationContext applicationContext) {

if (this.webApplicationContext == null && applicationContext instanceof WebApplicationContext) {

this.webApplicationContext = (WebApplicationContext) applicationContext;

this.webApplicationContextInjected = true;

}

}

 

 

posted @ 2019-12-31 16:14  zzfx  阅读(486)  评论(0编辑  收藏  举报