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
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));
}
}
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
configurer.setLocation(new ClassPathResource("context.properties"));
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"}, false);
applicationContext.addBeanFactoryPostProcessor(configurer);
applicationContext.refresh();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With