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

spring學(xué)習(xí)之util:properties的使用

 更新時(shí)間:2024年01月13日 14:20:00   作者:@Hmily@  
這篇文章主要介紹了spring學(xué)習(xí)之util:properties的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

<util:properties>可用于注入Properties對(duì)象,也可以用于讀取properties文件

1、手動(dòng)配置內(nèi)容

<util:properties id="properties">
    <prop key="name">zhangsan</prop>
    <prop key="age">age</prop>
    <prop key="gender">gender</prop>
</util:properties>
<bean id="phone" class="org.spring.teach.Phone">
    <property name="properties" ref="prop"/>
</bean>
public class Phone {
    private Properties properties;
 
    public void setProperties(Properties properties) {
        this.properties = properties;
    }
 
    @Override
    public String toString() {
        return "Phone{" +
                "properties=" + properties +
                '}';
    }
}
public class TestCase {
 
    private AbstractApplicationContext app;
 
    @Before
    public void before() {
        app = new ClassPathXmlApplicationContext("classpath:spring.xml");
    }
 
    @After
    public void after() {
        app.close();
    }
 
    @Test
    public void test() {
        Phone phone = app.getBean("phone", Phone.class);
        System.out.println(phone);
    }
}

一月 25, 2019 10:53:26 上午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7c53a9eb: startup date [Fri Jan 25 10:53:26 CST 2019]; root of context hierarchy
一月 25, 2019 10:53:26 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [spring.xml]
Phone{properties={age=age, name=zhangsan, gender=gender}}
一月 25, 2019 10:53:27 上午 org.springframework.context.support.ClassPathXmlApplicationContext doClose
信息: Closing org.springframework.context.support.ClassPathXmlApplicationContext@7c53a9eb: startup date [Fri Jan 25 10:53:26 CST 2019]; root of context hierarchy
 
Process finished with exit code 0

2、通過(guò)讀取文件獲取內(nèi)容

<util:properties id="properties" location="classpath:db.properties"/>
<bean id="phone" class="org.spring.teach.Phone">
    <property name="properties" ref="prop"/>
</bean>
public class Phone {
    private Properties properties;
 
    public void setProperties(Properties properties) {
        this.properties = properties;
    }
 
    @Override
    public String toString() {
        return "Phone{" +
                "properties=" + properties +
                '}';
    }
}
public class TestCase {
 
    private AbstractApplicationContext app;
 
    @Before
    public void before() {
        app = new ClassPathXmlApplicationContext("classpath:spring.xml");
    }
 
    @After
    public void after() {
        app.close();
    }
 
    @Test
    public void test() {
        Phone phone = app.getBean("phone", Phone.class);
        System.out.println(phone);
    }
}

"C:\Program Files\Java\jdk1.8.0_191\bin\java" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\Program Files\ideaIU-2018.1.win\lib\idea_rt.jar=57490:D:\Program Files\ideaIU-2018.1.win\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\ideaIU-2018.1.win\lib\idea_rt.jar;D:\Program Files\ideaIU-2018.1.win\plugins\junit\lib\junit-rt.jar;D:\Program Files\ideaIU-2018.1.win\plugins\junit\lib\junit5-rt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\rt.jar;F:\Workspace_idea\springday01\target\test-classes;F:\Workspace_idea\springday01\target\classes;F:\Repository\org\springframework\spring-webmvc\4.3.18.RELEASE\spring-webmvc-4.3.18.RELEASE.jar;F:\Repository\org\springframework\spring-aop\4.3.18.RELEASE\spring-aop-4.3.18.RELEASE.jar;F:\Repository\org\springframework\spring-beans\4.3.18.RELEASE\spring-beans-4.3.18.RELEASE.jar;F:\Repository\org\springframework\spring-context\4.3.18.RELEASE\spring-context-4.3.18.RELEASE.jar;F:\Repository\org\springframework\spring-core\4.3.18.RELEASE\spring-core-4.3.18.RELEASE.jar;F:\Repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;F:\Repository\org\springframework\spring-expression\4.3.18.RELEASE\spring-expression-4.3.18.RELEASE.jar;F:\Repository\org\springframework\spring-web\4.3.18.RELEASE\spring-web-4.3.18.RELEASE.jar;F:\Repository\junit\junit\4.11\junit-4.11.jar;F:\Repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;F:\apache-tomcat-8.5.37\lib\jsp-api.jar;F:\apache-tomcat-8.5.37\lib\servlet-api.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 test.TestCase,test04
一月 25, 2019 10:57:57 上午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7c53a9eb: startup date [Fri Jan 25 10:57:57 CST 2019]; root of context hierarchy
一月 25, 2019 10:57:57 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [spring.xml]
一月 25, 2019 10:57:58 上午 org.springframework.context.support.ClassPathXmlApplicationContext doClose
Phone{properties={user=root, url=jdbc:oracle:thin:@localhost:1521:orcl, driver=oracle.jdbc.driver.OracleDriver, initSize=1, pwd=root, maxSize=3}}
信息: Closing org.springframework.context.support.ClassPathXmlApplicationContext@7c53a9eb: startup date [Fri Jan 25 10:57:57 CST 2019]; root of context hierarchy
 
Process finished with exit code 0 

3、手動(dòng)配置內(nèi)容和讀取文件一起使用

<util:properties id="properties" location="classpath:db.properties">
    <prop key="name">zhangsan</prop>
    <prop key="age">age</prop>
    <prop key="gender">gender</prop>
</util:properties>
<bean id="phone" class="org.spring.teach.Phone">
    <property name="properties" ref="prop"/>
</bean>
public class Phone {
    private Properties properties;
 
    public void setProperties(Properties properties) {
        this.properties = properties;
    }
 
    @Override
    public String toString() {
        return "Phone{" +
                "properties=" + properties +
                '}';
    }
}
public class TestCase {
 
    private AbstractApplicationContext app;
 
    @Before
    public void before() {
        app = new ClassPathXmlApplicationContext("classpath:spring.xml");
    }
 
    @After
    public void after() {
        app.close();
    }
 
    @Test
    public void test() {
        Phone phone = app.getBean("phone", Phone.class);
        System.out.println(phone);
    }
}

一月 25, 2019 10:59:32 上午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7c53a9eb: startup date [Fri Jan 25 10:59:32 CST 2019]; root of context hierarchy
一月 25, 2019 10:59:32 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [spring.xml]
Phone{properties={name=zhangsan, url=jdbc:oracle:thin:@localhost:1521:orcl, initSize=1, user=root, pwd=root, gender=gender, maxSize=3, age=age, driver=oracle.jdbc.driver.OracleDriver}}一月 25, 2019 10:59:33 上午 org.springframework.context.support.ClassPathXmlApplicationContext doClose
 
信息: Closing org.springframework.context.support.ClassPathXmlApplicationContext@7c53a9eb: startup date [Fri Jan 25 10:59:32 CST 2019]; root of context hierarchy
 
Process finished with exit code 0

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot沒(méi)有主清單屬性的解決方法

    SpringBoot沒(méi)有主清單屬性的解決方法

    在本篇文章里小編給大家整理的是關(guān)于解決SpringBoot沒(méi)有主清單屬性知識(shí)點(diǎn),需要的朋友們學(xué)習(xí)下。
    2019-11-11
  • java中拼接字符串的5種方法效率對(duì)比

    java中拼接字符串的5種方法效率對(duì)比

    這篇文章主要給大家介紹了關(guān)于java中拼接字符串的5種方法效率對(duì)比的相關(guān)資料,文中通過(guò)示例代碼和圖片介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-01-01
  • java讀取Excel導(dǎo)入去除空行簡(jiǎn)單方法

    java讀取Excel導(dǎo)入去除空行簡(jiǎn)單方法

    這篇文章主要給大家介紹了關(guān)于java讀取Excel導(dǎo)入去除空行的簡(jiǎn)單方法,在日常開(kāi)發(fā)中,想必都遇到過(guò)批處理的需求,文中給出了詳細(xì)的示例代碼,需要的朋友可以參考下
    2023-07-07
  • 解決java web應(yīng)用線上系統(tǒng)偶發(fā)宕機(jī)的情況

    解決java web應(yīng)用線上系統(tǒng)偶發(fā)宕機(jī)的情況

    這篇文章主要介紹了解決java web應(yīng)用線上系統(tǒng)偶發(fā)宕機(jī)的情況,具有好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-09-09
  • Java接口統(tǒng)一樣式返回模板簡(jiǎn)介

    Java接口統(tǒng)一樣式返回模板簡(jiǎn)介

    這篇文章主要介紹了Java接口統(tǒng)一樣式返回模板簡(jiǎn)介,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10
  • 在java代碼中獲取JVM參數(shù)的方法

    在java代碼中獲取JVM參數(shù)的方法

    下面小編就為大家?guī)?lái)一篇在java代碼中獲取JVM參數(shù)的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-01-01
  • Java中Jackson快速入門

    Java中Jackson快速入門

    這篇文章主要介紹了Java中Jackson快速入門,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • 深入理解SpringBoot事務(wù)傳播機(jī)制

    深入理解SpringBoot事務(wù)傳播機(jī)制

    本文介紹了SpringBoot中事務(wù)傳播機(jī)制的原理及其常用配置,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-12-12
  • SpringBoot+Redis執(zhí)行l(wèi)ua腳本的5種方式總結(jié)

    SpringBoot+Redis執(zhí)行l(wèi)ua腳本的5種方式總結(jié)

    Lua是一種快速、輕量級(jí)的腳本語(yǔ)言,廣泛應(yīng)用于各種領(lǐng)域,包括數(shù)據(jù)庫(kù),Redis作為一個(gè)內(nèi)嵌Lua解釋器的NoSQL數(shù)據(jù)庫(kù),允許通過(guò)Lua腳本在服務(wù)器端執(zhí)行一些復(fù)雜的操作,本文給大家介紹了使用SpringBoot Redis執(zhí)行l(wèi)ua腳本的五種方式,需要的朋友可以參考下
    2023-11-11
  • SpringBoot項(xiàng)目部署時(shí)application.yml文件的加載優(yōu)先級(jí)和啟動(dòng)腳本問(wèn)題

    SpringBoot項(xiàng)目部署時(shí)application.yml文件的加載優(yōu)先級(jí)和啟動(dòng)腳本問(wèn)題

    Spring Boot在啟動(dòng)時(shí)會(huì)根據(jù)一定的優(yōu)先級(jí)順序加載配置文件,優(yōu)先級(jí)從高到低依次是:命令行參數(shù)、Jar包外部config目錄下的配置文件、Jar包同級(jí)目錄下的配置文件、classpath下的/config目錄、classpath根路徑
    2024-09-09

最新評(píng)論

稻城县| 探索| 鹿邑县| 大埔区| 汶川县| 清涧县| 甘南县| 黄陵县| 赤壁市| 嵊泗县| 宜春市| 武平县| 正蓝旗| 南木林县| 肃北| 望城县| 宝兴县| 固阳县| 城步| 丹凤县| 新干县| 道孚县| 新沂市| 泌阳县| 健康| 吉首市| 德格县| 中卫市| 湘西| 天长市| 射阳县| 海原县| 虹口区| 罗平县| 牡丹江市| 清徐县| 水富县| 汕头市| 焉耆| 通江县| 叙永县|