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

          }
          實現(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ù)源配置。

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


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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 吉木萨尔县| 寻乌县| 措勤县| 海安县| 新竹市| 江华| 连城县| 银川市| 乌拉特中旗| 盈江县| 固始县| 西华县| 灵山县| 绩溪县| 叙永县| 许昌县| 武宁县| 通化市| 沧州市| 靖边县| 郴州市| 苏尼特右旗| 沁阳市| 元江| 恩施市| 榆社县| 陆良县| 达拉特旗| 车险| 济源市| 正安县| 卓尼县| 万安县| 武鸣县| 岑巩县| 昌吉市| 藁城市| 汤原县| 山西省| 高阳县| 东乡|