在web.xml中配置
<!--配置spring全局参数 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationcontext.xml</param-value>
</context-param>
<!--配置监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
调用时通过以下方式获取ApplicationContext对象
ApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());