SpringMVC中的ContextLoaderListener设计困惑
2015-12-25 00:07
267 查看
最近在学习Spring MVC原理相关部分,就按顺序从ContextLoaderListener来看,但是我在阅读此类的设计中,遇到了些困惑的地方,现纪录如下,希望能遇到高手能帮我答疑解惑:
ContextLoaderListener 类的定义:
困惑一:
ContextLoaderListener类已经继承了ContextLoader,为何又声明了一个私有的ContextLoader类的 对象属性contextLoader?而这个 contextLoader 在上下文的 意义愚以为仅仅是显示的说明 contextLoader 其实就是"this"。(我仿照ContextLoaderListener写了个去掉contextLoader属性的类,容器正常启动)
困惑二:
ContextLoaderListener doc注释为:
Spring's root {@link WebApplicationContext},可以翻译为Spring的 顶级/根 WebApplicationContext吗?那是否有非root的呢?
也许我比较愚钝没能发现其中的奥秘,也可能我比较较真,非要打破沙锅问到底,思考了许久,还希望大牛能帮我答疑解惑。
ContextLoaderListener 类的定义:
public class ContextLoaderListener extends ContextLoader implements ServletContextListener { private ContextLoader contextLoader; public ContextLoaderListener() { } public ContextLoaderListener(WebApplicationContext context) { super(context); } public void contextInitialized(ServletContextEvent event) { this.contextLoader = createContextLoader(); if (this.contextLoader == null) { this.contextLoader = this; } this.contextLoader.initWebApplicationContext(event.getServletContext()); } @Deprecated protected ContextLoader createContextLoader() { return null; } @Deprecated public ContextLoader getContextLoader() { return this.contextLoader; } public void contextDestroyed(ServletContextEvent event) { if (this.contextLoader != null) { this.contextLoader.closeWebApplicationContext(event.getServletContext()); } ContextCleanupListener.cleanupAttributes(event.getServletContext()); } }
困惑一:
ContextLoaderListener类已经继承了ContextLoader,为何又声明了一个私有的ContextLoader类的 对象属性contextLoader?而这个 contextLoader 在上下文的 意义愚以为仅仅是显示的说明 contextLoader 其实就是"this"。(我仿照ContextLoaderListener写了个去掉contextLoader属性的类,容器正常启动)
困惑二:
ContextLoaderListener doc注释为:
Bootstrap listener to start up and shut down Spring's root {@link WebApplicationContext}...
Spring's root {@link WebApplicationContext},可以翻译为Spring的 顶级/根 WebApplicationContext吗?那是否有非root的呢?
也许我比较愚钝没能发现其中的奥秘,也可能我比较较真,非要打破沙锅问到底,思考了许久,还希望大牛能帮我答疑解惑。
相关文章推荐
- ServletContext 和ServletContextListener
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- SpringMvc项目 Tomacat启动错误 ContextLoaderListener
- SpringMvc整合DWR做文件上传
- 使用Java.Mail 进行邮件发送
- Eclipse 反编译插件 jadClipse
- java.lang.NoClassDefFoundError:TagSupport
- PopupWindow返回参数至Activity两种方式:接口和Rxjava
- java提供服务者框架
- eclipse 去掉js validation 配置方法
- 如何在spring框架中解决多数据源的问题
- SpringMVC 通用Controller
- Gradle在Eclipse中构架多模块工程笔记
- Gradle构建Eclipse项目中加入自有Source Folder
- Gradle2.7+Eclipse4.5+Jetty Debug
- Spring4+Lucene4.6+庖丁解牛分词
- Java:笔记:数据类型
- Java:笔记:生产AIP文档
- spring定时任务执行两次
- eclipseLink基于JAXB方式实现javabean与xml的互转