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

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

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

1.spring配置文件

復(fù)制代碼 代碼如下:

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

2.讀取屬性方法

復(fù)制代碼 代碼如下:

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


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

直接讀取方式:
復(fù)制代碼 代碼如下:

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配置方式讀取:

復(fù)制代碼 代碼如下:

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配置:

復(fù)制代碼 代碼如下:

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

相關(guān)文章

最新評(píng)論

柳州市| 宜兰市| 历史| 广安市| 外汇| 红桥区| 扬中市| 宁乡县| 郁南县| 石渠县| 泾阳县| 山西省| 肇源县| 徐水县| 仪征市| 阿巴嘎旗| 海城市| 吴桥县| 临沧市| 喀喇| 定结县| 贵港市| 铁力市| 凤庆县| 白山市| 大理市| 翁源县| 台中市| 莱州市| 西宁市| 萝北县| 洞口县| 新源县| 曲阳县| 无棣县| 梓潼县| 连山| 祁门县| 定陶县| 筠连县| 太保市|