數據加載中……
          不實用spring讀取ApplicationContet.xml文件中的數據源配置
          在web應用沒有啟用之前我們需要對數據庫進行操作,此事spring沒有加載完成,我們依然可以使用jdbc對數據庫進行操作。
          實現方法如下
          配置一個struts監聽器,
          實現ServletContextListener接口
          public class HuaweiDBListener implements ServletContextListener {

          }
          實現接口中方法
          public void contextInitialized(ServletContextEvent context) {
              String serverPath = context.getServletContext().getRealPath("/"); 
              ApplicationContext appC= new FileSystemXmlApplicationContext(serverPath + "WEB-INF\\spring\\applicationContext.xml"); 
              ComboPooledDataSource c = (ComboPooledDataSource) appC.getBean("dataSource"); 
              System.out.println("DriverClass=="+ c.getDriverClass());
          }


          使用ComboPooledDataSource對象直接從ApplicationContet.xml中得到數據源配置。
          使用jdbc操作數據庫就不列舉了。

          posted on 2011-09-06 22:02 陳碧滔 閱讀(211) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 济宁市| 皮山县| 金山区| 辰溪县| 岱山县| 黄骅市| 安仁县| 宁陕县| 金门县| 望城县| 怀集县| 丁青县| 铜川市| 沙湾县| 鄂尔多斯市| 东平县| 东山县| 澜沧| 安宁市| 忻城县| 浦江县| 达拉特旗| 本溪| 苗栗市| 丽水市| 桑日县| 仪陇县| 长白| 安庆市| 沐川县| 屏边| 东乌珠穆沁旗| 巴林左旗| 区。| 万载县| 增城市| 东源县| 新野县| 炎陵县| 寿光市| 东平县|