2

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

Nani
  • 363
  • 2
  • 4
  • 8

2 Answers2

1

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
chepaiytrath
  • 678
  • 1
  • 9
  • 20
0

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.

John Smith
  • 2,282
  • 1
  • 14
  • 22
  • do you know any of such library which stands on top of properties which supports such references. – Nani Aug 02 '13 at 11:18
  • please see: http://stackoverflow.com/questions/872272/how-to-reference-another-property-in-java-util-properties, eproperties is the name of the library that is mentioned... – John Smith Aug 02 '13 at 11:47
  • i want to add dependency but not jar..do you know how to do it..if so please let me know – Nani Aug 02 '13 at 12:07