標籤:io ar 使用 sp div on art bs ad
第一種配置方式:<servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext*.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> 第二種配置方式:<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml,classpath:*applicationContext-*.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener> 區別:ContextLoaderListener中載入的context成功後,spring 將 applicationContext存放在ServletContext中key值為"org.springframework.web.context.WebApplicationContext.ROOT"的attribute中。DispatcherServlet載入的context成功後,如果 publishContext屬性的值設定為true的話(預設為true) 會將applicationContext存放在org.springframework.web.servlet.FrameworkServlet.CONTEXT. + (servletName)的attribute中。結論:從上面的分析可以看出,DispatcherServlet所載入的applicationContext可以認為是mvc私人的context,由於儲存在servletContext中的key值與通過ContextLoaderListener載入進來的applicationContext使用的key值不相同,因此如果只使用DispatcherServlet載入context的話,如果程式中有地方使用WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext) 來試圖擷取applicati
ContextLoaderListener與DispatcherServlet所載入的applicationContext的區別