What is the best way to manage configuration data

前端 未结 8 1198
时光取名叫无心
时光取名叫无心 2020-12-07 17:18

I am working on a product suite which has 4 products. Right now, all of the configuration data is either in the XML or properties files.This approach is not maintainable as

8条回答
  •  温柔的废话
    2020-12-07 17:53

    If your applications work with a database, you can create a "configuration" table as follows:

    create table configuration (mode char(3), key varchar(255), value varchar(1023));
    

    You would initialize it using an init script, say init.sql with contents along the lines of:

    insert into configuration values ('pro', 'param1', 'value1'); -- production
    insert into configuration values ('dev', 'param1', 'value1'); -- development
    insert into configuration values ('tst', 'param1', 'value1'); -- testing
    ...
    

    The benefits of this approach are as follows:

    • you version the script together with your code
    • you can easily extend it to include per-user or per-group settings by adding a user/group id
    • you can change the settings at runtime if you need to do so
    • you get to use the same stack (JPA + DAO, Cayenne...) you normally use to handle core application data to handle configuration data

提交回复
热议问题