I have defined few properties in my application.properties:
path.tools=/app/tools
In code I try to fetch it as:
System.getenv("path.tools");
But it returns null.
I also tried:
System.getProperty("path.tools");
App is running in docker.
What am I missing in my setup?
>Solution :
For you to be able to get it with System.getenv you would have needed to define it as an environment variable first.
For you to be able to read it from System.getProperty you would have needed to have set that system property first with System.setProperties OR to have tried reading one of predefined System properties
To read properties that are read by Spring either:
1. Autowire the property with @Value
@Value("${path.tools}")
String pathTools;
2. Read them from Environment class (that you can autowire)
@Autowired
Environment environment;
public void foo() {
environment.getProperty("path.tools");
}