how to read System environment variable in Spring applicationContext

You are close :o)
Spring 3.0 adds Spring Expression Language.
You can use

<util:properties id="dbProperties" 
    location="classpath:config_#{systemProperties['env']}/db.properties" />

Combined with java ... -Denv=QA should solve your problem.

Note also a comment by @yiling:

In order to access system environment variable, that is OS level
variables as amoe commented, we can simply use “systemEnvironment”
instead of “systemProperties” in that EL. Like
#{systemEnvironment['ENV_VARIABLE_NAME']}

Leave a Comment