I\'m trying to figure out how my Spring app can determine where it is deployed and load the appropriate datasource. We have 3 environments...my local, the development server, a
The other answers here have good ideas in them, but I'm answering because my own approach is something of a combination of the three. First, don't reference properties files of multiple environments directly in your Spring XML. Just work from a single file. Then, using a combination of Spring's
,
,
, and SpEL, you can easily set up a very flexible configuration.
gets wired with the output of the
.
uses SpEL to check for a system property with a given name. If available, it uses that as the location of a properties file to load. If not,
, which tries to do a JDNI lookup for the location. If that also doesn't find anything, thendefault-value
attribute of
.This setup makes it simple to specify a properties file location no matter what environment you're in because of all the options.