【Spring学习笔记】ApplicationContext Vs WebApplicationContext
2016-09-13 10:54
253 查看
ApplicationContext
applicationContext.xml is the root context configuration for every web application. Spring loads applicationContext.xml file and creates the ApplicationContext for the whole application. There will be only one application context per web application. If you are not explicitly declaring the context configuration file name in web.xml using the contextConfigLocation param, Spring will search for the applicationContext.xml under WEB-INF folder and throw FileNotFoundException if it could not find this file.
WebApplicationContext
Apart from ApplicationContext, there can be multiple WebApplicationContext in a single web application. In simple words, each DispatcherServlet associated with single WebApplicationContext. xxx-servlet.xml file is specific to the DispatcherServlet and a web application can have more than one DispatcherServlet configured to handle the requests. In such scenrios, each DispatcherServlet would have a separate xxx-servlet.xml configured. But, applicationContext.xml will be common for all the servlet configuration files. Spring will by default load file named “xxx-servlet.xml” from your webapps WEB-INF folder where xxx is the servlet name in web.xml. If you want to change the name of that file name or change the location, add initi-param with contextConfigLocation as param name.
参考:
http://stackoverflow.com/questions/11708967/what-is-the-difference-between-applicationcontext-and-webapplicationcontext-in-s
applicationContext.xml is the root context configuration for every web application. Spring loads applicationContext.xml file and creates the ApplicationContext for the whole application. There will be only one application context per web application. If you are not explicitly declaring the context configuration file name in web.xml using the contextConfigLocation param, Spring will search for the applicationContext.xml under WEB-INF folder and throw FileNotFoundException if it could not find this file.
WebApplicationContext
Apart from ApplicationContext, there can be multiple WebApplicationContext in a single web application. In simple words, each DispatcherServlet associated with single WebApplicationContext. xxx-servlet.xml file is specific to the DispatcherServlet and a web application can have more than one DispatcherServlet configured to handle the requests. In such scenrios, each DispatcherServlet would have a separate xxx-servlet.xml configured. But, applicationContext.xml will be common for all the servlet configuration files. Spring will by default load file named “xxx-servlet.xml” from your webapps WEB-INF folder where xxx is the servlet name in web.xml. If you want to change the name of that file name or change the location, add initi-param with contextConfigLocation as param name.
参考:
http://stackoverflow.com/questions/11708967/what-is-the-difference-between-applicationcontext-and-webapplicationcontext-in-s
相关文章推荐
- JavaWeb学习笔记-spring-03-ioc-WebApplicationContext
- Spring学习历程---WebApplicationContext初始化
- Spring 学习记录7 初识XmlWebApplicationContext
- Spring学习----------BeanFactory VS ApplicationContext
- spring学习笔记(3)——配置文件applicationContext.xml的加载
- 【Spring学习笔记-2】Myeclipse下第一个Spring程序-通过ClassPathXmlApplicationContext加载配置文件
- 【11-10】spring学习笔记-ApplicationContextAware
- Spring学习(十)BeanFactory VS ApplicationContext
- spring学习笔记---------applicationContext.xml 1
- Spring 学习记录8 初识XmlWebApplicationContext(2)
- Spring学习笔记之Spring中applicationContext.xml的bean里的id和name属性区别
- JavaWeb学习笔记-spring-02-ioc-BeanFactory&ApplicationContext
- Spring源码学习之一 ContextLoaderListener及XmlWebApplicationContext
- spring源码学习笔记-初始化(六) ClassPathXmlApplicationContext
- [学习笔记] Spring beanfactory applicationcontext
- 一直停留“信息: Initializing Spring root WebApplicationContext”
- Error configuring application listener of class org.springframework.web.context.ContextLoaderListene
- org.springframework.web.context.support.WebApplicationContextUtils