Spring学习笔记2——web项目初始化webapplicationcontext
2015-02-27 21:00
369 查看
1、新建web项目来加载spring
webapplicationcontext是专门为web应用准备,它允许从相对于web根目录的路径中装载配置文件,完成初始化操作。从webapplicationcontext中可以获得servletcontext的引用。
2、webapplicationcontext的初始化
通过配置自启动的servlet或web容器监听器
方式一:配置自启动的servlet
方式二:web容器监听器
说明:spring有三种启动方式,使用ContextLoaderServlet,ContextLoaderListener和ContextLoaderPlugIn
spring3.0的change log
http://static.springsource.org/spring/docs/3.0.x/changelog.txt
里面注明:
removed ContextLoaderServlet and Log4jConfigServlet
的确是去掉了
可以采用余下两种启动方式ContextLoaderListener和ContextLoaderPlugIn
建议使用ContextLoaderListener
3、如下是配置的spring配置文件和加载spring配置文件的web.xml
webapplicationcontext是专门为web应用准备,它允许从相对于web根目录的路径中装载配置文件,完成初始化操作。从webapplicationcontext中可以获得servletcontext的引用。
2、webapplicationcontext的初始化
通过配置自启动的servlet或web容器监听器
方式一:配置自启动的servlet
<!-- 声明自动启动的servlet --> <servlet> <servlet-name>springContextLoaderServlet</servlet-name> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <!-- 启动顺序 --> <load-on-startup>1</load-on-startup> </servlet>
方式二:web容器监听器
<!-- 声明web容器监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
说明:spring有三种启动方式,使用ContextLoaderServlet,ContextLoaderListener和ContextLoaderPlugIn
spring3.0的change log
http://static.springsource.org/spring/docs/3.0.x/changelog.txt
里面注明:
removed ContextLoaderServlet and Log4jConfigServlet
的确是去掉了
可以采用余下两种启动方式ContextLoaderListener和ContextLoaderPlugIn
建议使用ContextLoaderListener
3、如下是配置的spring配置文件和加载spring配置文件的web.xml
<!-- 配置Spring的用于初始化容器对象的监听器方式来初始化webapplicationcontext -->
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>/WEB-INF/applicationContext.xml</param-value> -->
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<!-- 声明web容器监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
相关文章推荐
- springMVC学习笔记,SpringMV与web项目的整合(xml方式)
- Spring 学习笔记(2)—— ApplicationContext 及 WebApplicationContext 的初始化
- Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目
- vue学习笔记-----vue+webpack初始化项目(vue1.0的安装)
- springMVC学习笔记,SpringMV与web项目的整合(注解方式)
- Java 学习笔记09:Spring搭建MVC WEB项目
- spring: web学习笔记1--异常处理:No adapter for handler
- spring源码学习笔记-初始化(六) ClassPathXmlApplicationContext
- java web第一个项目学习笔记
- spring源码学习笔记-初始化(4)
- Spring学习笔记 初始化属性为null值的方法
- spring源码学习笔记-初始化(二) PostProcessor
- Spring Web MVC 的学习笔记
- Spring学习笔记 通过PropertyPlaceholderConfigurer来使用properties文件初始化Map类型属性
- ant学习笔记(六)ant编译web项目,并打成war包,同时加入数据库操作
- Spring学习笔记 关于Bean属性的初始化 - 使用inner bean以及List, Map与Set的初始化
- Dynamic Web Project 项目学习笔记
- Spring学习笔记-Bean初始化&销毁
- spring源码学习笔记-初始化(三)-BeanFactory
- spring源码学习笔记-初始化(四)-PostProcessor