1

I am using Intellij on my Windows laptop and I want to use environment variables in application.properties. Below is an example of application.properties.

server=%APP_SERVER%

I have added a new user environment variable as shown below through IntelliJ Run/Deebug Configurations.

APP_SERVER=localhost

But I see that when I run the application, it is failing to replace this environment property. I tried using ${APP_SERVER} instead of %APP_SERVER% but still no use. Any idea why this is not working.

Deepak Janyavula
  • 348
  • 4
  • 17
  • How are you reading your application.properties file? – yole Sep 23 '19 at 15:48
  • 1
    There is an answer to similar problem. Please read this https://stackoverflow.com/a/2263944/4635750 – Nodir Nasirov Sep 23 '19 at 18:52
  • @NodirNasirov, I don't prefer getEnv solution as the other post describes. Thanks anyway – Deepak Janyavula Sep 23 '19 at 20:46
  • @yole, I am using Apache Commons PropertiesConfiguration Configuration conf = new PropertiesConfiguration("application.properties"); I know that I can use getEnv approach but I don't prefer this approach. I would like to use CI/CD pipeline to replace these variables in application.properties later while deploying onto server. And also, if I am running locally (or debugging) from IntelliJ, I like them to get replaced by environment variables – Deepak Janyavula Sep 23 '19 at 20:47
  • `I am using Apache Commons PropertiesConfiguration` - have you consulted the library documentation about how to properly reference environment variables: https://commons.apache.org/proper/commons-configuration/userguide/howto_basicfeatures.html it seems one must use `env` prefix for this: `java.home = ${env:JAVA_HOME}`. – Andrey Sep 24 '19 at 09:50
  • Yes, ${env:JAVA_HOME} also doesn't work – Deepak Janyavula Nov 01 '19 at 09:08

0 Answers0