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 閱讀(318) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 乳山市| 涞水县| 阳曲县| 东安县| 黑龙江省| 陆丰市| 墨竹工卡县| 新干县| 瑞昌市| 琼海市| 定日县| 凤凰县| 青田县| 额尔古纳市| 汝阳县| 页游| 常宁市| 静乐县| 富平县| 东莞市| 县级市| 上杭县| 鱼台县| 华宁县| 抚宁县| 阿巴嘎旗| 祥云县| 咸阳市| 扎赉特旗| 玉山县| 旬邑县| 紫云| 莆田市| 临邑县| 清远市| 德清县| 香河县| 海晏县| 蕉岭县| 公安县| 临江市|