Java Web Application Configuration Patterns

前端 未结 10 739
夕颜
夕颜 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 20:01

    What we do works pretty well.

    On startup, our programs read a configuration file in a hardcoded path. Let's say it's:

    /config/fun_prog/config.xml
    

    Each program has a different hard coded path (FunProgram is in fun_prog, Super Server is in sup_serv, whatever), so we don't have to worry about them walking over each other.

    The XML files are read by a little configuration library we created. The XML file contains the DB connection information, usually mail server configuration data, email addresses to send notifications to, whether it should operate in test mode, URLs of external services, etc.

    So when we need to make changes, we copy the config file, edit what we want, and restart the program. Since we have a standard server setup, any program can be deployed on any server by just copying these files around (and the neccessary httpd.conf tinkering).

    It's not fancy, but it works very well. It's extremely simple to understand, add new configuration options, backup, and edit. Works on all platforms (unix is obvious, Windows translates paths starting with / into c:\ so it works without edits there too).

    Our workstations basically run the same software as the server, just with a few changes in that config file.

提交回复
热议问题