Java Login


Hello guys, is for Java and J2EE developers, all examples are simple and easy to understand 

It is developed and maintained by Vaibhav Sharma. The views expressed on this website are his own and do not necessarily reflect the views of his former, current or future employers. I am professional Web development. I work for an IT company as Senior Consultant. Primary I write about spring, hibernate and web-services. I am trying to present here new technologies.

     << Previous
Next >>     

Property Place Holder

PropertyPlaceholderConfigurer is a property resource configurer that resolves placeholders in bean property values of context definitions. It pick values from a properties file into bean definitions.

We can use it to externalize property values from a bean definition in a separate file using the standard Java Properties format. Doing so enables the person deploying an application to customize environment-specific properties such as database URLs and passwords, without the complexity or risk of modifying the main XML definition file or files for the container.

Let's consider the simple case where we want to read some properties that are constant variables from an external Properties file. We need an XML-based configuration, where a PropertyPlaceholderConfigurer bean must be defined. At runtime, the PropertyPlaceholderConfigurer is applied to the metadata that will replace the properties of the bean. The values to replace are specified as placeholders of the form 0.

Location of the properties files
  • By default, Spring looks for the properties files in the application's directory. So if we specify:
    <property name="location" value="WEB-INF/"/>

    Then it will find the file under WEB-INF directory of the application (in case of a Spring MVC application).
  • We can use the prefix classpath: to tell Spring loads a properties file in the application's classpath. For example:
    <property name="location" value=""/>

  • In case of a Spring MVC application, the file should be present in the WEB-INF/classes directory (or in the source directory (src) in Eclipse IDE). Use the prefix file:/// or file: to load a properties file from an absolute path. For example:
    <property name="location" value="file:///D:/config/"/>

  • In case if you are configure multiple file, then we can use the list collection for configure multiple file. For example:
    <property name="locations" >

package propertyPlaceHolder;

public class User {
private String name;
private String password;

public String getName() {
return name;
public void setName(String name) {
this .name = name;
public String getPassword() {
return password;
public void setPassword(String password) {
this .password = password;


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

<bean id="user" class="propertyPlaceHolder.User">
<property name="name" value="${name}"/>
<property name="password" value="${password}"/>
<bean class="org.springframework.beans.factory.config
<property name="location">
name=User 1
password=Password 1

package propertyPlaceHolder;

import org.springframework.context.ApplicationContext;

public class Main {

public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
User user = (User)context.getBean("user");

System.out.println("User Name is "+user.getName());
System.out.println("User Password is "+user.getPassword());


     << Previous
Next >>