Posted on 2006-12-21 21:00
itspy 閱讀(2931)
評論(5) 編輯 收藏 所屬分類:
JAVA技術
?在web.xml設置監聽器:org.springframework.web.context.ContextLoaderListener
?<listener>
??<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
?</listener>
?
?在此類(ContextLoaderListener)中有如下方法:?
?public void contextInitialized(ServletContextEvent event) {
??this.contextLoader = createContextLoader();
??this.contextLoader.initWebApplicationContext(event.getServletContext());
?}
?
?org.springframework.web.context.ContextLoader
?在此類中有如下變量:?public static final String CONTEXT_CLASS_PARAM = "contextClass";
????public static final String CONFIG_LOCATION_PARAM = "contextConfigLocation";
?
?如下方法:initWebApplicationContext,createWebApplicationContext
?第一個方法調用了第二個方法,第二個方法則通過如下代碼初始為了一個上下文環境
?String configLocation = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
?
?注:另外一點如下的DispatcherServlet設置會自動加載petstore-servlet.xml環境,原理我查了半天我也不知道怎么搞的.
?<servlet>
??<servlet-name>petstore</servlet-name>
??<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
??<load-on-startup>2</load-on-startup>
?</servlet>