Stanislav Bashkyrtsev
Stanislav Bashkyrtsev

Reputation: 15308

Different ways of configuring webapps

I'm writing scripts to deploy apps under Tomcat. There are different ways of configuring these apps:

Could someone provide other options and share their opinions on the listed above? Consider these criteria: easiness of configuring, portability, standards, explicitness (don't like magic, other people may not understand it), OS (main OS is Linux, but others may want to run it on Windows).

Upvotes: 2

Views: 215

Answers (3)

Alexander Rühl
Alexander Rühl

Reputation: 6939

I'd recommend putting properties into a database table (which of course implies, your application has a datasource).

We prefer this method in our web applications for the following reasons:

  • Properties are separated from the deployed artifact and application's install directory
  • Peoperties can easily be accessed by database tools
  • Properties can have additional attributes, like a type or a default value
  • Properties can easily be changed during runtime (provided the web application has some admin page to reload them)
  • Depending on the environment (e.g. development, test, production) you can have different sets of properties and load them in the same way as other master data

In cases where you don't have a database at all, another solution is just to use system properties and read them by System.getProperty(key), which is ok for a system under your control and not too many properties.

Upvotes: 1

Oscar Castiblanco
Oscar Castiblanco

Reputation: 1646

You can use configuration based on env properties by using files. What I mean is that you can write a Context.xml file under the META-INF of your web application setting up the environment or configuration following this rules.

I find that using env properties provides easy configuration, is based on context and dependency injection. You can use the new java API's eg. the @Resource annotation. It will work under any application server, etc.

Upvotes: 2

ftraian
ftraian

Reputation: 658

In my experience it worked well using and environment variable for the conf dir: {APP_NAME}_CONF_DIR. If this is not set the application will default loading from /etc/{app_name}/conf . Most of the time you will not have to set the env. variable as you will use the default dir.

Upvotes: 0

Related Questions