jar包不用新添加,使用原来web02添加的jar就够了,添加applicationContext文件进来只需再web.xml文件中添加一个监听器即可
添加代码如下:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 默认配置在WEB-INF目录下 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value> <!-- <param-value>/WEB-INF/spring*.xml</param-value> -->
</context-param>
这里遇到过这样一个面试题:什么是监听器、什么是过滤器,什么是拦截器;
监听器是注册再web.xml文件中的,监听一些事件的发生,比如ContextLoaderListener 实现了servletContextListener,它能够监听 ServletContext 对象的生命周期,实际上就是监听 Web 应用的生命周期。
显然ContextLoaderListener是监听web项目启动事件的,web启动就去加载applicationContext文件。