Spring Propertyplaceholderconfigurer Example

In this tutorial we see what is the use of Spring’s Propertyplaceholderconfigurer class in detail.

In general , in software development we will maintain some details in properties files , like database credendetials , smt server deatils …etc., but those details we maintain in different properties files and will write a logic and will read those detail for usage.

In Spring we have a bean class Propertyplaceholderconfigurer which is used to configure the property files and easy to access the details from property file by using a special format — ${key name }

Let us have a example how to use Propertyplaceholderconfigurer.

For example we have a database details like as below..

Configure the above property file in beans configuration file.

have a look in to below code snippet how we configure and access property file.

 

Different Location type configurations:

1. Spring looks for the properties files in the application’s directory by default, So if we specify like as below

<property name=”location” value=”WEB-INF/Prod_database.properties” />

then it will find under WEB-INF directory of the application.
2. We can use the prefix classpath: to tell Spring to loads the properties file in the application’s classpath,for example configuration

<property name=”location” value=”classpath:Prod_database.properties” />

 

 

 

 

Posted in string and tagged , .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.