New to spring boot.
While exploring spring boot env variables, came to know that,
env variables can be accessed by ${KeyName}
from code.
Got a question like,
Case 1:
In @Configuration files, we are accessing keys in application.properties using @Value(value = "${KeyName}")
.
So, we are using almost same syntax for accessing env variables and accessing keys in application.properties.
Case 2: When trying to access the keys in application.properties using system.getEnv("keyname"), I got only null.
Case 3: Recently worked on configmap in kubernetes with spring boot.
Config file looks like,
spec:
containers:
- name: demo-configconsumercontainer
image: springbootappimage:latest
ports:
- containerPort: 8080
envFrom:
- configMapRef:
name: example-configmap
All the values from configMap is exported as environmental variables and
I am accessing those values by @Value(value = "${KeyName}")
and by system.getEnv(KeyName)
.
- My question is, how case 3 is working when case 2 is not.
- Is Spring boot made such a way that, it is allowing to access by
${KeyName}
and not bysystem.getEnv(KeyName)
? (ie. Case 2)
Could some one clarify my questions here.