How to obtain the value of a property using the Environment API in Spring Boot

56 Views Asked by At

I have a specific requirement to obtain the value of a property using the Environment API without field/constructor injection. Since I am using a private method, injecting a property with the @Value annotation is also not working without a class variable.

This is the private method signature.

public int getCustomProperty(String key) {
    Environment env;
    ...// I'm not able to find out an example code
    return env.getProperty(key, Integer.class);
}
0

There are 0 best solutions below