zoukankan      html  css  js  c++  java
  • JAVA本地程序使用FileSystemXmlApplicationContext读取applicationdatasorce.xml进行数据库操作

    使用绝对路径读取,就绝对不会出错

    程序代码如下,这个类是BookDaoTest

     1        String appContextPath = BookDaoTest.class.getClassLoader().getResource("").getPath() + "../";
     2             File file = new File(appContextPath);
     3             String abPath = null;
     4             try {
     5                 abPath = file.getCanonicalPath();
     6             } catch (IOException e) {
     7                 e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
     8             }
     9             String[] ctxConfig = {"file:" + abPath + "/applicationContext-beans.xml", "file:" + abPath + "/applicationContext-datasource.xml", "file:" + abPath + "/applicationContext-security.xml"};
    10             ApplicationContext context = new FileSystemXmlApplicationContext(ctxConfig);
    11 
    12             BookDao bookDao = (BookDao) context.getBean("bookDao");
  • 相关阅读:
    ARC管理内存(一)
    懒加载lazyload
    View的封装
    Plist文件与数据解析
    ubuntu16.04 安装python3.6
    ubuntu16.04 安装 wxPython方法
    第三章
    第二章
    协方差的意义
    内存区--Java
  • 原文地址:https://www.cnblogs.com/zemliu/p/2644952.html
Copyright © 2011-2022 走看看