欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

詳解Spring加載Properties配置文件的四種方式

一、通過 context:property-placeholder 標(biāo)簽實(shí)現(xiàn)配置文件加載

創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比太原網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式太原網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋太原地區(qū)。費(fèi)用合理售后完善,十年實(shí)體公司更值得信賴。

1、用法示例: 在spring.xml配置文件中添加標(biāo)簽    

復(fù)制代碼 代碼如下:
<context:property-placeholder ignore-unresolvable="true" location="classpath:redis-key.properties"/> 

2、在 spring.xml 中使用配置文件屬性:

<!-- 基本屬性 url、user、password --> 
<property name="url" value="${jdbc.url}" /> 
<property name="username" value="${jdbc.username}" /> 
<property name="password" value="${jdbc.password}" /> 

3、在java文件中使用:

@Value("${jdbc_url}") 
ivate String jdbcUrl; // 注意:這里變量不能定義成static 

二、通過 util:properties 標(biāo)簽實(shí)現(xiàn)配置文件加載

1、用法示例: 在spring.xml配置文件中添加標(biāo)簽 

復(fù)制代碼 代碼如下:
<util:properties id="util_Spring"  local-override="true" location="classpath:jeesite.properties"/>

2、在spring.xml 中使用配置文件屬性:

<property name="username" value="#{util_Spring['jdbc.username']}" /> 
<property name="password" value="#{util_Spring['jdbc.password']}" /> 

3、在java文件中使用:

@Value(value="#{util_Spring['UTIL_SERVICE_ONE']}") 
 private String UTIL_SERVICE_ONE; 

三、通過 @PropertySource 注解實(shí)現(xiàn)配置文件加載

1、用法示例:在java類文件中使用 PropertySource 注解:

@PropertySource(value={"classpath:redis-key.properties"}) 
public class ReadProperties { 
@Value(value="${jdbc.username}") 
 private String USER_NAME; 
} 

2、在java文件中使用:

@Value(value="${jdbc.username}") 
 private String USER_NAME; 

四、通過 PropertyPlaceholderConfigurer 類讀取配置文件

1、用法示例:在 spring.xml 中使用 <bean>標(biāo)簽進(jìn)行配置

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
  <property name="locations"> 
   <list> 
    <value>classpath:redis-key.properties</value> 
   </list> 
  </property> 
  </bean> 

2、 PropertyPlaceholderConfigurer  配置方法,等價(jià)于 方式一,用法參考方法一。

五、 還可以使用  org.springframework.beans.factory.config.PropertiesFactoryBean  加載,這里不再逐一列舉了。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

新聞名稱:詳解Spring加載Properties配置文件的四種方式
URL標(biāo)題:http://chinadenli.net/article46/pdsehg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、做網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)、微信小程序、品牌網(wǎng)站制作、標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)