1、のContextLoaderListenerリスナー
public class ContextLoaderListener extends ContextLoader implements ServletContextListener{
public ContextLoaderListener() {
}
public ContextLoaderListener(WebApplicationContext context) {
super(context);
}
//初始化容器
public void contextInitialized(ServletContextEvent event) {
this.initWebApplicationContext(event.getServletContext());
}
public void contextDestroyed(ServletContextEvent event) {
this.closeWebApplicationContext(event.getServletContext());
ContextCleanupListener.cleanupAttributes(event.getServletContext());
}
}
1.コンテナオブジェクトを作成します。
this.context = this.createWebApplicationContext(servletContext);
//查找需要使用的容器类,默认从 contextClass 属性获取,没有该属性,从 ContextLoader.properties 文件中进行读取,采用的是 XmlWebApplicationContext 容器
Class<?> contextClass = this.determineContextClass(sc);
return (ConfigurableWebApplicationContext)BeanUtils.instantiateClass(contextClass);
2、リフレッシュコンテナ
this.configureAndRefreshWebApplicationContext(cwac, servletContext);
//1.将 ServletContext 放到容器中
wac.setServletContext(sc);
//2.读取 contextConfigLocation 配置文件路径
configLocationParam = sc.getInitParameter("contextConfigLocation");
//3.刷新容器
wac.refresh();
図3に示すように、プロパティを設定するためのServletContext
//属性名称为 WebApplicationContext.class.getName() + ".ROOT";
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);
2、のDispatcherServlet成分
、アセンブリは、サーブレットは、最終的に1であり、それはinitメソッドを実行し、複数のサービスを実行する際に、ビジネス・コール、HttpServletBeanにINIT
public final void init() throws ServletException {
//...省略
initServletBean();
}
FrameworkServletに実装2、initServletBean、
protected final void initServletBean() throws ServletException {
this.webApplicationContext = initWebApplicationContext();
//空实现
initFrameworkServlet();
}
//init实现
WebApplicationContext rootContext =
WebApplicationContextUtils.getWebApplicationContext(getServletContext());
WebApplicationContext wac = null;
//1.使用的是 XmlWebApplicationContext 容器
wac = createWebApplicationContext(rootContext);
//2.该方法在 DispatcherServlet 中重写,用来初始化 Dispatcher 的相关组件
onRefresh()
図3に示すように、初期化コンポーネント。。。継続するには