Java Web Application Configuration Patterns

前端 未结 10 737
夕颜
夕颜 2020-12-22 18:58

Are there any patterns or best practices that can be used to simplify changing configuration profiles for java web applications across multiple environments. e.g. JDBC URLs,

10条回答
  •  佛祖请我去吃肉
    2020-12-22 19:39

    There are a few possible ways to approach this:

    • use property files like you do, but add a "meta properties" file that is used to select the property file used by defining a map between an environment value (for instance localhost hostname) onto the property file name to load.

    • put your properties into a database and define the database connection to the property tables in your application server as resource that is picked up by your web-app.

    • don't put the property files in your .war or .ear, but create a properties-deployhost.jar archives containing the property files per target host. bind the appropriate .jar file to the deployed web-app by adding it to the class path (for instance via shared libraries in the application server configuration per web-app.)

    Only the first of these does not need extra manual steps when deploying at the expense of having to update your config source and building new deploy files when your target systems are renamed.

    I'm sure lots of variantions on these and your approach are possible, what is the best choice depends on your situation.

提交回复
热议问题