1Spring整合web项目
1)出现的问题:每次访问action时候,都会加载spring配置文件
2)解决方案:在服务器启动的时候,创建对象加载配置文件;底层使用监听器、SevletContext对象。
3)spring不需要我们自己写代码实现,帮封装
- 帮封装了监听器,只需配置监听器就可以了(在哪个文件中,用什么来配置(在web.xml中使用listener进行配置))
<!-- 配置监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
- 配置监听器之前要导入spring整合web项目jar包(spring-web.RELEASE.jar)
- 指定加载spring配置文件位置
<!-- 指定spring配置文件位置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:bean3.xml</param-value> </context-param>