1.加载web.xml文件。web.xml里面定义了一下几方面的内容:
(1).spring配置文件的存放位置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/conf/appContext*.xml</param-value>
<!-- <param-value>classpath*:/**/appContext*.xml</param-value> -->
</context-param>
(2).自定义的几个Action:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>com.cnpc.pms.base.common.action.DispatcherAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>dispatcher.action</url-pattern>
</servlet-mapping>
(3).过滤器(filter):
<filter>
<filter-name>initialFilter</filter-name>
<filter-class>com.cnpc.pms.base.filter.InitialFilter</filter-class>
</filter>
<filter>
<filter-name>authFilter</filter-name>
<filter-class>com.cnpc.pms.bizbase.filter.AuthFilter</filter-class>
</filter>
(4).监听器(listener):
在web.xml里面最下面一行有一个Listener:
<listener>
<listener-class>com.cnpc.pms.base.filter.PMSContextLoaderListener</listener-class>
</listener>
2.PMSContextLoaderListener类,里面定义了再加载完web.xml后,也就是在contextInitialized后,执行PMSContextLoaderListener类里重写了的contextInitialized()方法。
下面列出contextInitialized()方法的内容和注释:
public void contextInitialized(ServletContextEvent event) {
log.debug("Start Initialize Web PMS Context");
Slf4jWebConfigurer.initLogging(event.getServletContext());
log.debug("Start Initialize Web ContextLoader ====>");
contextLoader = createContextLoader();//加载appContext.xml文件
//注册里面定义的beans:
//(1).PMSPropertyPlaceholderConfigurer加载application.properties文件,
// 该文件包含了数据库的连接信息.
// PMSPropertyPlaceholderConfigurer类中重写了processProperties()方法,
// 该方法又从dataSource.xml中读取了一部分数据库信息.
//(2).PMSReloadableResourceBundleMessageSource加载国际化文件i18n/*query*.xml
contextLoader.initWebApplicationContext(event.getServletContext());
log.debug("<====End of Initialize Web ContextLoader");
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
GenericWebApplicationContext genericWac = new GenericWebApplicationContext();
genericWac.setParent(wac);
log.debug("<====End of Initialize GenericWebApplicationContext");
SpringHelper.setApplicationContext(genericWac);//设置ThreadLocal<ApplicationContext>的值
appContext.initialize();//(1)注册module文件夹下的xml中定义的bean,(2)加载query文件夹下的xml
event.getServletContext().setAttribute(APPLICATION_CONTEXT_ATTRIBUTE, genericWac);
}