How to get the properties file data info Spring App ?
Properties
file :-
The text file that
maintains the entries as key value pairs is called properties file. We
generally use properties file to maintain JDBC properties like
dirverClassName,Url,username and password and
make them as flexible to modify without touching the source code. Spring
application is added as new app to the existing project and if existing
application can achieve this flexibility through xml file (Spring bean
configuration file) if Spring application is added as new app to the existing
project and if existing applications of that project and if existing
application of that project are getting JDBC properties from properties file
then are should make sure that spring application also get JDBC properties from properties file.
In ApplicationContext
container environment we need to configure
“org.springframework.beans.factory.config.PropertyPlaceHolderConfigure” class
as spring bean to make container to locate given properties file and to
recognize place holders in spring bean configuration file .
Place holders ---à${……………}
Each placeholder represents 1 key of the property file to
get values from properties file.
DBDetails.properties(com/rg/commons)
Jdbc.driver=oracle.jdbc.driver.OracleDriver
Jdbc.url= jdbc:oracle:thin:@lovalhost:1521:xe
db.user=system
db.pwd=manager
applicationContext.xml
<bean id=”ppc”
class=”org.springframework.beans.factory.config.PropertyPlaceHolderConfigure”>
<property name=”location” value=”src/com/rg/commons/ DBDetails.properties”/>
</bean>
<bean id=”drds” class=”org.springframework.jdbc.datasource.DriverManagerDataSouce”>
<property name=”driverClassName”
value=”${jdbc.driver}”/>
<property name=”url” value=”${jdbc.url}”/>
<property name=”username” value=”${jdbc.user}”/>
<property name=”password” value=”${jdbc.pwe}”}/>
</bean>