This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Correct me if I'm wrong, but even if I used: <context:property-placeholder location="mypropertiesFile.properties" /> ,then I'm still specifying an exact properties file name.
This would mean that I would have to re-build my application and replace the contents of "mypropertiesFile.properties" (for instance with a build script or something) with production properties when I deploy it to production, correct?
I was hoping to create two properties files (i.e. mytestproperties.properties, and myprodproperties.properties) and include them both in the ear, and when the app was started, and spring initialized the bean, it could programmatically determine which properties file to load based on some criteria, like server name or a jndi lookup, or whatever.
There are a couple of trivial ways to implement this.
One is to create a class that lists the config files to load, so that in addition to the default it could, say, load a config file based on the host name. You could do the same thing with property files and a custom property placeholder configurator.
Another is to create a property placeholder configurator that looks for property names prefixed with a host name, and if it exists, use that value in place of the "bare", or unqualified, name (or names with a prefix, like this:)Both of these solutions are very, very simple to create.
Another very simple alternative will be to actually use a property placeholder and set the key in the environment variable. that way you do not need to actually build any files. You can simply change the environment variable on different servers/JVM and get the job done neatly.