How to access application properties in spring boot application?

In spring boot applications it is a good practice to keep all the configuration inside file. We can have multiple files based on the environments. Following is an example of environment based file:

-rw-r--r--   1 joe  staff   922 Dec  4 14:26
-rw-r--r--   1 joe  staff   930 Dec  4 14:26
-rw-r--r--   1 joe  staff   879 Dec  4 14:26
-rw-r--r--   1 joe  staff  8439 Dec  4 14:26

Many developers keep the settings or config inside java code in spring boot. Keeping settings or config inside java code is not a good practice.

Using @value annotation

We can use the @Value annotation and access the property like below:

    private String targetEnvironment;

Using @Autowired to Environment

We can use spring provided @Autowired to inject Environment to the bean.

private Environment environments;

public void getApplicationProperties() {
    String path = environments.getProperty("");

Using @ConfigurationProperties to Environment

@ConfigurationProperties can be used like below to get the application properties.

@ConfigurationProperties(prefix = "arc")
public class ArcEndpointConfig {

    private Map environments = new HashMap<>();

    public static class Endpoint{
        private Map endpoint = new HashMap<>();