PropertyPlaceholderConfigurer: can i have a dynamic location value

java

Solution

You can define the file location as system property, eg -Dprops.file=file:c:/1.properties

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
    <value>$props.file</value>
  </property>
</bean>

or

<context:property-placeholder location="${props.file}"/>

or you can scan the file system

public class ScanningPropertyPlaceholderConfigurer extends org.springframework.beans.factory.config.PropertyPlaceholderConfigurer {
    @Override
       public void setLocation(Resource location) {
       File file = findFile(fileName);  // implement file finder
       super.setLocation(new FileSystemResource(file));
    }
}

Problem

right now i have this in my xml file: ``` <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/dashboardsupervisor" /> <property name="username" value="root" /> <property name="password" value="${jdbc.password}" /> </bean> ``` and ``` <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>file:C:/jdbc.properties</value> </property> </bean> ``` Now , my problem is that i do not know the exact location of this file(jdbc.properties) , as this application will going to run on different computers , in some places its installed in c: ,sometimes may be on f:.. So if i dont know the path of this file , if there is anyway i could find it . thanks

Original source