Junky's IT Notebook

          統計

          留言簿(8)

          積分與排名

          WebSphere Studio

          閱讀排行榜

          評論排行榜

          讀取配置文件的幾種方法

          在讀spring in aciton 時,他用的BeanFactory factory = new XmlBeanFactory(new FileInputStream("hello.xml"));
          可是現在的用的1.2.6版本的構造器(XmlBeanFactory)只能接收Resource接口了,所以調不出來是正常的事情,假設現在有一個文件hello.xml
          讀取方法

          1:ApplicationContext cx=new FileSystemXmlApplicationContext("hello.xml");//指定的路徑去找文件
          2:ApplicationContext factory = new ClassPathXmlApplicationContext("hello.xml");//還會在classpath去找
          3:Resource fa = new FileSystemResource("hello.xml");
          ? ?BeanFactory factory=new XmlBeanFactory(fa);
          4:這個要設制classpath了,麻煩
           ?Resource res = new ClassPathResource("com/springinaction/chapter01/hello/hello.xml");
           ?BeanFactory factory=new XmlBeanFactory(res);
          好了,用了上面那種方法都可以調用getBean("your bean name")了,
          eg:?BeanFactory factory=new XmlBeanFactory(fa);
          ????? hello he=(hello)factory.getBean("hello");
          ????????????? he.getHello();

          posted on 2006-06-04 23:27 junky 閱讀(323) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 孟村| 昌图县| 道真| 和静县| 阳城县| 赤峰市| 清苑县| 外汇| 恩平市| 肇源县| 淳化县| 政和县| 丁青县| 开阳县| 达尔| 安西县| 吉林省| 达日县| 综艺| 延长县| 永德县| 万源市| 绥宁县| 安义县| 靖安县| 龙游县| 河北省| 南丰县| 历史| 华宁县| 南阳市| 潜山县| 新余市| 天柱县| 栾城县| 黎川县| 东阿县| 苗栗县| 南通市| 贵阳市| 平利县|