In the systemEnvironment, if we have two keys with different capitalization and want to take the lowercase key, but due to capitalization issues, we will not be able to obtain the correct value。
if we have key "env"=qa and key "ENV"=QA
// env=qa ENV=QA
System.out.println(applicationContext.getEnvironment().getProperty("env"));//QA
System.out.println(System.getenv("env"));//qa
if we use use System.getenv("env") will get the right value but if applicationContext.getEnvironment().getProperty("env") will get the wrong value 'QA'
our springboot version is 2.5.12
I thought it was a problem with the SystemEnvironmentPropertyMapper, which tends to take uppercase keys, resulting in missing the correct key.
Comment From: snicoll
I am afraid this is working as designed. Environment variables must be upper case and dash separated on most OSes and those keys need to be mapped to regular properties using the canonical format.
If you need such specific handling of variables, you should call the underlying API directly as you're doing in your example.