最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

讀取spring配置文件的方法(spring讀取資源文件)

 更新時間:2014年02月24日 09:53:09   作者:  
這篇文章主要介紹了讀取spring配置文件的方法,需要的朋友可以參考下

1.spring配置文件

復制代碼 代碼如下:

<bean id="configproperties"
         class="org.springframework.beans.factory.config.PropertiesFactoryBean">
          <property name="location" value="classpath:jdbc.properties"/>
    </bean>

2.讀取屬性方法

復制代碼 代碼如下:

ApplicationContext c=new ClassPathXmlApplicationContext("classpath:applicationContext-datasource.xml");
Properties p=(Properties)c.getBean("configproperties");
System.out.println(p.getProperty("jdbcOrcale.driverClassName"));


另一個朋友提供的讀取spring配置文件的方法,也分享一下吧

直接讀取方式:
復制代碼 代碼如下:

public void test() throws IOException
 {
  Resource resource = ApplicationContextFactory.getApplicationContext().getResource("classpath:com/springdemo/resource/test.txt");

  File file = resource.getFile();
  byte[] buffer =new byte[(int) file.length()];
  FileInputStream is =new FileInputStream(file);

  is.read(buffer, 0, buffer.length);

  is.close();
  String str = new String(buffer);
  System.out.println(str);

 }

通過spring配置方式讀取:

復制代碼 代碼如下:

package com.springdemo.resource;

import org.springframework.core.io.Resource;

public class ResourceBean {

 private Resource resource;

 public Resource getResource() {
  return resource;
 }

 public void setResource(Resource resource) {
  this.resource = resource;
 }
}

spring bean配置:

復制代碼 代碼如下:

 <!-- 可以直接將一個文件路徑賦值給Resource類型的resource屬性,spring會根據(jù)路徑自動轉換成對應的Resource -->
 <bean id="resourceBean" class="com.springdemo.resource.ResourceBean" >
  <property name="resource" value="classpath:/com/springdemo/resource/test.txt" ></property>
 </bean>

相關文章

最新評論

民县| 盱眙县| 桂平市| 宣武区| 忻州市| 开远市| 蚌埠市| 宽城| 古浪县| 桂平市| 内乡县| 中卫市| 诸城市| 西吉县| 安多县| 富平县| 伊宁县| 江城| 怀安县| 金山区| 台州市| 海安县| 五华县| 利川市| 巴青县| 南华县| 类乌齐县| 阆中市| 休宁县| 育儿| 澎湖县| 两当县| 新津县| 汕头市| 玉山县| 沭阳县| 兰溪市| 光泽县| 喀什市| 上饶县| 古蔺县|