Arif Acar Arif Acar - 1 year ago 501
Java Question

How to read data from java properties file using Spring Boot

I have an spring boot application and I wanna read some variable from my file. Infact above codes do that. But I think there is a good method for this alternative.

Properties prop = new Properties();
InputStream input = null;

try {
input = new FileInputStream("");
gMapReportUrl = prop.getProperty("gMapReportUrl");
} catch (IOException ex) {
} finally {

Answer Source

You can use @PropertySource to externalize your configuration to a properties file. There is number of way to do get properties:

1. Assign the property values to fields by using @Value with PropertySourcesPlaceholderConfigurer to resolve ${} in @Value:

public class ApplicationConfiguration {

    private String gMapReportUrl;

    public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
        return new PropertySourcesPlaceholderConfigurer();


2. Get the property values by using Environment:

public class ApplicationConfiguration {

    private Environment env;

    public void foo() {


Hope this can help

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download