Junky's IT Notebook

          統(tǒng)計

          留言簿(8)

          積分與排名

          WebSphere Studio

          閱讀排行榜

          評論排行榜

          讀取配置文件的幾種方法

          在讀spring in aciton 時,他用的BeanFactory factory = new XmlBeanFactory(new FileInputStream("hello.xml"));
          可是現(xiàn)在的用的1.2.6版本的構(gòu)造器(XmlBeanFactory)只能接收Resource接口了,所以調(diào)不出來是正常的事情,假設(shè)現(xiàn)在有一個文件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:這個要設(shè)制classpath了,麻煩
           ?Resource res = new ClassPathResource("com/springinaction/chapter01/hello/hello.xml");
           ?BeanFactory factory=new XmlBeanFactory(res);
          好了,用了上面那種方法都可以調(diào)用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

          主站蜘蛛池模板: 收藏| 湖北省| 衡阳市| 澄迈县| 正阳县| 庆城县| 上思县| 渭南市| 嘉峪关市| 依兰县| 涟水县| 太保市| 邵阳县| 镇赉县| 平乡县| 昔阳县| 马公市| 龙川县| 通辽市| 乌恰县| 垦利县| 车险| 许昌市| 孟连| 丰城市| 玉树县| 巴彦淖尔市| 唐山市| 广安市| 永寿县| 黑山县| 嘉祥县| 隆德县| 崇义县| 浏阳市| 满城县| 连城县| 浙江省| 乌鲁木齐市| 拜城县| 达日县|