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

          }
          實(shí)現(xiàn)接口中方法
          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中得到數(shù)據(jù)源配置。
          使用jdbc操作數(shù)據(jù)庫就不列舉了。

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


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 章丘市| 台江县| 灵川县| 永清县| 江达县| 义马市| 广西| 海丰县| 琼结县| 五华县| 剑河县| 红河县| 巴中市| 曲靖市| 武功县| 华池县| 湘潭市| 神农架林区| 集贤县| 和政县| 垦利县| 土默特右旗| 扶沟县| 宁晋县| 隆回县| 乌拉特中旗| 波密县| 东阿县| 新宾| 松原市| 桐梓县| 阿拉善盟| 辰溪县| 布尔津县| 从化市| 崇信县| 且末县| 沁源县| 丹阳市| 文水县| 准格尔旗|