Spring整合web项目

1 演示问题
(1)action调用service,service调用dao
每次访问action时候,都会加载spring配置文件

2 解决方案:
(1)在服务器启动时候,创建对象加载配置文件
(2)底层使用监听器、ServletContext对象

3 在spring里面不需要我们自己写代码实现,帮封装
(1)封装了一个监听器,只需要 配置监听器 就可以了
《listener>
《listener-class> org. springframework .web. context. contextLoaderListener《/listener-class>
《/listener>
(2)配置监听器之前做事情:导入spring整合web项目jar包
spring-web-4.2.4.release.jar
(3)指定加载spring配置文件位置
《context-param>
《param-name》contextconfiglocation《/para-name>
《param-value》classpath:bean1.xml《/para-value>
《/context-param》

猜你喜欢

转载自blog.csdn.net/jcsyl_mshot/article/details/80392121