第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

apache PropertiesConfiguration 無(wú)法解析占位符

apache PropertiesConfiguration 無(wú)法解析占位符

RISEBY 2023-06-28 15:56:30
假設(shè)我有以下兩個(gè)配置文件:文件一:key1 = ${common.key1}key2 = ${common.key2}文件2:common.key1 = value1common.key2 = value2我有以下代碼:import org.apache.commons.configuration.PropertiesConfiguration;...PropertiesConfiguration newConfig = new PropertiesConfiguration();File configFile1 = new File("...paht to file 1");File configFile2 = new File("...path to file 2");newConfig.setDelimiterParsingDisabled(true);newConfig.load(configFile2);newConfig.load(configFile1);Iterator<String> props = newConfig.getKeys();while (props.hasNext()) {    String propName = props.next();    String propValue = newConfig.getProperty(propName).toString();    System.out.println(propName + " = " + propValue);}我有以下輸出:common.key1 = value1common.key2 = value2key1 = ${common.key1}key2 = ${common.key2}為什么占位符沒(méi)有解析?
查看完整描述

2 回答

?
喵喔喔

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊

以下是用戶應(yīng)注意的與變量插值相關(guān)的更多信息:

  • ...

  • 變量插值由所有屬性訪問(wèn)方法完成。一個(gè)例外是返回原始屬性值的通用方法。getProperty()

這正是您在代碼中使用的。

API 文檔getProperty()也提到了這一點(diǎn):

從配置中獲取屬性。...在此級(jí)別上尚未執(zhí)行變量替換。

使用其他可用的方法來(lái)PropertiesConfiguration獲取實(shí)際的插值。例如,調(diào)用getProperties()將其PropertiesConfiguration轉(zhuǎn)換為java.util.Properties對(duì)象并對(duì)其進(jìn)行迭代。


查看完整回答
反對(duì) 回復(fù) 2023-06-28
?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

也可以通過(guò)占位符替換以通用方式使用它,如下所示:

config.get(Object.class, propName);

getProperty與方法不同,get帶參數(shù)的方法Object.class將返回原始類的值,并插入變量。


查看完整回答
反對(duì) 回復(fù) 2023-06-28
  • 2 回答
  • 0 關(guān)注
  • 234 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)