将web02项目配置上spring--applicationContext.xml

来源:互联网 发布:淘宝店运营方案 编辑:程序博客网 时间:2024/04/30 12:37

 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文件。

0 0
原创粉丝点击