0

It seems that when deploying my Spring app to AppFog, that the environment variables are not being detected.

I have the environment variables declared in my console:

Environment Variables

And I try to reference these from within my app code, like so:

<context:property-placeholder 
    location="classpath:server.common.properties,
    classpath:server.${concorde-env}.properties"/>

However, this generates an error:

Caused by: java.io.FileNotFoundException: class path resource [server.${concorde-env}.properties] cannot be opened because it does not exist

This approach works fine in other (non AppFog) environments.

I logged out the properties by calling:

 log.info("Properties: " + System.getProperties().toString());

And it doesn't show those properties as available.

However, if I do a af env <<MY_APP_NAME>>, it shows the variables as present:

+--------------------------+------------------+
| Variable                 | Value            |
+--------------------------+------------------+
| concorde-env             | test             |
| spring.profiles.active   | runtime,test     |
+--------------------------+------------------+

What am I missing to make these variables exposed to my app at runtime?

Marty Pitt
  • 28,822
  • 36
  • 122
  • 195

1 Answers1

1

Try accessing the value like this: System.getenv("concorde-env") to see if the environment var can even be accessed in code.

Based on the error message "class path resource [server.${concorde-env}.properties] cannot be opened because it does not exist" it seems like ${concorde-env} is not even being evaluated or replaced even with empty string.

It looks like Spring has other ways of accessing env vars. Try #{systemEnvironment['concorde-env']} instead of ${concorde-env}

Tim Santeford
  • 27,385
  • 16
  • 74
  • 101
  • Hey Tim, thanks for your answer! I faced the same problem and I fixed it with `System.getenv("MY_ENV")`. Important note! AppFog doesn't allow variables with separated dots, only with `_` or `-`. If you use dots it will return `null`. – maqjav Aug 30 '13 at 09:23