数据加载中……
不实用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 陈碧滔 阅读(205) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: