1.加载Spring核心配置文件
加载spring配置文件,根据创建对象
ApplicationContext ac=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
2.实现思想:把加载配置文件和创建对象过程,在服务器启动时候完成;
3.实现原理
(1)ServletContext对象
(2)监听器
(3)具体使用
该监听器是servletContext(jsp application)的生命周期监听器
Tomcat启动时contextInitialzed用创建spring的容器webapplcationcontext
tomcat关闭时contextDestroued调用容器close方法关闭
在maven中配置web
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.12.RELEASE</version>
</dependency>
在web.xml中配置监听器:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>