First, some context:
I’m currently working on a project in which I use the Spring framework on Google’s AppEngine (GAE) to fetch some data from one of Google’s services. To do so, I make use of Google’s OAuth facilities. For this, I need to use a clientSecret and clientId that are specific to my application. As these are static configuration values, I use Spring’s <util:properties> (link to documentation) functionality to insert these values into the appropriate classes.
XML config:
<util:properties id="googleProperties" location="WEB-INF/google.properties" />
Class usage:
@Value("#{googleProperties['google.data.api.client.id']}")
private String clientId;
My Question:
As it turns out, the values of clientId and clientSecret need to be different for production (when deployed on App Engine) as for development (on my local machine). In order to solve this without constantly needing to change the values in the properties file when deploying, I have been looking into Spring’s configuration profiles that would allow me to specify different property files for production and for development. Although I have an idea how Spring profiles work based on the documentation, I am not at all sure what the appropriate solution would be in this particular situation.
In other words, how can I inject different property files based on whether my application is deployed locally or on GAE?
A couple of options:
System Variables
You can use a prefix to control environment specific properties, this can be done by using system variables:
In this case it will always look under:
by default, unless a
ENV_SYSTEMsystem variable is set. If it is set toqa, for example, it will automatically look under:Spring Profiles
Another approach is to make beans profile specific. For example:
The appropriate
googlePropertieswill loaded depending on a profile set. For example this will loadWEB-INF/google-dev.properties: