Nani
Nani

Reputation: 363

Can One property value be assigned to another property in other properties file

I have two .properties files in which i have same value for two properties each file. So I thought to refer one value to other as for example:

1.config.properties

 path= /opt/logs/bundle

2.default.properties

default =/opt/logs/bundle (same as path in config.properties)

Now here as default property value is same as path so i thought to give like:

default = {path}

but here i am not able to get that path. Can anyone please help me out. Thanks

Upvotes: 2

Views: 7611

Answers (2)

chepaiytrath
chepaiytrath

Reputation: 718

In my project, EncryptablePropertySourcesPlaceholderConfigurer has been used and then 'Resource [] locations' property of its parent 'PropertiesLoaderSupport' has been assigned each of the properties file that I want to load. I guess this is the reason I don't face any error.

For Example:

<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>

And in database-config.properties:

 database.driver.class=com.mysql.jdbc.Driver
 database.connection.url=${database.connection.url}
 database.username=root
 database.password=${database.password}

Also in filter.properties:

 database.connection.url=jdbc:mysql://localhost:3306/MySQLDBName?rewriteBatchedStatements=true
 database.password=root

Upvotes: 1

John Smith
John Smith

Reputation: 2330

the Properties class in java does not have a functionality to reference other properties. If you have ever seen a .properties file, that uses references, the application that interprets that .properties file adds this functionality on top of the Properties class. E.g. you have to look up the property path yourself, if you find a value that begins with { and ends with }.

On the other hand, when using a specific configuration file format (like spring's bean.xml) of a certain library, that library may have added references inside their format. It is quite possible, that you can find a library that adds references on top of java's Properties facility or that Spring has something in it's huge pack of "whatever you need" already.

Upvotes: 0

Related Questions