开发者

How to persist configuration settings in Spring?

开发者 https://www.devze.com 2023-02-16 16:38 出处:网络
I have a set of configura开发者_运维问答tion settings (key/value) pair, which is meant for customization (through an admin panel for example) through Spring MVC. Are there any wide-accepted way of acc

I have a set of configura开发者_运维问答tion settings (key/value) pair, which is meant for customization (through an admin panel for example) through Spring MVC. Are there any wide-accepted way of accomplishing this?

One has suggested using a one-row table to persist, but other has dismissed this as a bad design. What are my options? I am thinking that a property file should be sufficient in this case, but it is not exactly clear to me how to map this property file to a java object, as a model, save and update it ...

Thanks for your help

Oliver


Where I work we often simply have a configuration table with two columns, one for key, one for value. This seems to work well. This is context-less, but can be put into context simply by adding another column for 'customer_id' for example, or 'site_id'.

class ConfigurationValue {
  String key, String value; 
  // blah, blah
}

Then just use the JDBC template to do reads/inserts/etc... No magic here.


java.util.Properties gives you a simply interface to read/write .properties files in Java. That might be suitable for your case, but depends largely on your application.

0

精彩评论

暂无评论...
验证码 换一张
取 消