<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.12.RELEASE</version>
</dependency>
spring,mavenwar类型项目:
配置监听器,获取容器 ,web.xml中配置:<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<!-- 该监听器是ServletContext(jsp中 application)的生命周期监听器,
Tomcat启动时 contextInitialized 用于创建spring的容器WebApplicationContext ,
Tomcat关闭时,contextDestroyed 调用容器的close方法关闭 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
//获取容器对象
ApplicationContext aContext=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());