Java Spring 项目整合优化(一)

加载Spring的配置文件:

每次访问action时,就会创建Context对象,效率就很低

解决:1、将Spring的配置文件的加载交给服务器容器,在服务器启动时加载

    2、底层使用监听器,ServletContext对象

 

Spring已实现了该方案

步骤:

  1、依赖Spring的web整合jar

    

   2、在工程的web.xml中加入Listener标签,在Listener里面加入Listener-class标签,标签里写Spring_web jar下的的ContextLoaderListener的全路径

  3、在web.xml中配置Spring的配置文件。在web.xml中加入context-param标签,在标签里加入param-name和param-value标签,name里写contextConfigLocation,value写你Spring文件的全路径,如果在src下:classpath:xx.xml

(如果你的Spring配置文件在WEB-INF下名字也叫applicationContext,忽略本步骤。)

 

        

 

posted @ 2017-09-17 14:23  猴子1  阅读(281)  评论(0编辑  收藏  举报