[英]How to substitute the value of one property into another in properties file?
[英]Can One property value be assigned to another property in other properties file
我有兩個.properties
文件,其中每個文件的兩個屬性具有相同的值。 所以我想將一個值引用到另一個值,例如:
1.config.properties
path= /opt/logs/bundle
2.default.properties
default =/opt/logs/bundle
(與 config.properties 中的路徑相同)
現在這里默認屬性值與路徑相同,所以我想給出如下:
default = {path}
但在這里我無法走這條路。 誰能幫幫我。 謝謝
Java中的Properties
類沒有引用其他屬性的功能。 如果您曾經見過使用引用的.properties
文件,則解釋該.properties
文件的應用程序會在Properties
類的頂部添加此功能。 例如,如果您找到以{
開頭並以}
結尾的值,則必須自己查找屬性路徑。
另一方面,當使用某個庫的特定配置文件格式(例如spring的bean.xml)時,該庫可能在其格式內添加了引用。 很可能,您可以找到一個在Java的Properties
設施之上添加引用的庫,或者說Spring
已經在它的“所需之物”中打包了一些東西。
在我的項目中,已使用EncryptablePropertySourcesPlaceholderConfigurer,然后為其父“ PropertiesLoaderSupport”的“資源[]位置”屬性分配了我要加載的每個屬性文件。 我想這就是我沒有遇到任何錯誤的原因。
例如:
<bean id="frameworkPropertyPlaceholderConfigurer"
class="org.jasypt.spring31.properties.EncryptablePropertySourcesPlaceholderConfigurer">
<constructor-arg ref="stringEncryptor" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<bean parent="frameworkConfigResourceFactoryBean">
<property name="resourceName" value="framework-config.properties" />
</bean>
<bean ................> </bean>
</list>
</property>
</bean>
並在database-config.properties中:
database.driver.class=com.mysql.jdbc.Driver
database.connection.url=${database.connection.url}
database.username=root
database.password=${database.password}
同樣在filter.properties中:
database.connection.url=jdbc:mysql://localhost:3306/MySQLDBName?rewriteBatchedStatements=true
database.password=root
就我而言,我想將一個屬性引用到同一個 .properties 文件中的另一個屬性中。 據我所知,正如之前已經提到的,你不能那樣做。 我的方法是在屬性文件加載器中更改它的值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.