數據加載中……
          不使用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中得到數據源配置。

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


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


          網站導航:
           
          主站蜘蛛池模板: 连山| 翁源县| 海城市| 邵武市| 区。| 柳河县| 富宁县| 扎鲁特旗| 怀仁县| 左贡县| 冀州市| 寿阳县| 宿迁市| 丰顺县| 松潘县| 永德县| 香港 | 鹿邑县| 徐州市| 镇赉县| 大安市| 安图县| 彭水| 威信县| 偃师市| 图片| 惠州市| 广昌县| 平定县| 贵南县| 乐安县| 精河县| 武鸣县| 房山区| 汤阴县| 皋兰县| 铁岭市| 中方县| 宣威市| 岚皋县| 叶城县|