How to read properties file in Spring.
Jan 23
Java, Programming, Spring 13 Comments
If you need to read properties file in your Spring application all you need is to configure a PropertyPlaceholderConfigurer bean in your application context.
Following example shows how to read property values from a properties file named config.properties. This file needs to be in your classpath so Spring can find it.
Let’s begin by creating a simple Java class that will use the properties values from the file.
package com.zparacha.spring.examples.config;
public class CreateUser {
//Spring will populate these fields through Dependency Injection.
private String name;
private String email;
private String URL;
public CreateUser(){}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getURL() {
return URL;
}
public void setURL(String url) {
URL = url;
}
public void displayUser() {
System.out.println("Name=" + this.name);
System.out.println("Email="+ this.email);
System.out.println("URL=" + this.URL);
}
}


