I do not know what is best, but here is what we do.
(Note that this only works for one installation for each application on the server and will fail if you want to use multiple deployments to the server, say, for deployments with multiple applications).
Entering CDI Values
We use a somewhat sophisticated approach to CDI injection to enter configuration values from .properties directly into beans, for example:
@Inject @ConfigurationValue(value="amazonS3FileContentsAccessKey") private String accessKey;
The corresponding @Producer bean reads configuration files from the class path and from the specified "local" location:
global / local .properties files
- Each EAR contains a “global”
.properties file in the class path for configuration values that rarely change and / or usually remain consistent across environments (for example, days for expiration). In addition, the global configuration file contains normal default values (for example, " localhost " for the database server name). Global properties files (there are several of them, see below) are supported in the source tree. - For each development / installation / server / deployment environment (possibly) this is a “local” properties file containing local parameters that overwrite global configuration parameters, such as database names, passwords, etc.
The expected path to the "local" property files is configured in the global configuration file (for example, /etc/myapp/local.properties ) or C:\myapp\local.properties .
In fact, we even allow the replacement of some variables in the file name for local configuration files, such as " ${hostname} ". The initial idea was that local properties could also be maintained in some central source control by distinguishing them by host name ( local.machineA.properties , local.machineB.properties ), but we are not using it at the moment, because that our production settings are the same on all machines (Amazon S3 keys, database password / host, etc.).
Assembly for developers, testing, production
We collect different EARs depending on the development stage using Maven profiles.
Optionally, the desired global.${profile.name}.properties file (where profile.name is, for example, dev or production ) is copied to the expected global.properties file in the class path.
For example, dev and testing share a common secret / bucket AmazonS3, which is configured once for all developers in the configuration.dev.properties file, and configuration.production.properties does not contain our production keys.
In addition, in our dev and testing environments, there is debugging enabled and configured, such as web.xml , but of course, staging and production do not. Our .properties approach cannot modify files like web.xml , but easily create Maven profiles.