Arif Acar Arif Acar - 3 months ago 65
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 {


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