Enlightensoft's Blog

Helping in your each step

  • Categories

  • Authors

How to use Properties File in Spring

Posted by Pankil Patel on August 22, 2010

Style 1: Configure property file to be used in spring xml

# Add new bean entry into your application context.

<bean id=”propertyConfigurer”
class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>
<property name=”location”>
<value>classpath:abcConfig.properties</value>
</property>
</bean>

# Create new property file into src folder
abcConfig.properties

# Use that property file value

<property name=”user”>
<value>${jdbc.user}</value>
</property>
<property name=”password”>
<value>${jdbc.password}</value>
</property>

Style 2: Configure property file to be used in spring xml as well as in Java files
Step 1: Do All steps as in Style 1

Step 2: Add one more property called property-override with your “property-placeholder”
<context:property-override
location=”classpath:envSettings.properties” />

Step 3: Create one Java Class called “PathConfiguration” and add all properties & it’s setter, getter into this class. After that configure this class in your spring xml file like bellow.

<bean name=”pathConfiguration”
class=”co.cc.enlightensoft.service.common.PathConfiguration”>
</bean>

<bean
class=”org.springframework.web.context.support.ServletContextAttributeExporter”>
<property name=”attributes”>
<map>
<entry key=”pathConf” value-ref=”pathConfiguration” />
</map>
</property>
</bean>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: