Oliver
Oliver

Reputation: 3682

How to persist configuration settings in Spring?

I have a set of configuration 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

Upvotes: 2

Views: 1467

Answers (2)

Trever Shick
Trever Shick

Reputation: 1784

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.

Upvotes: 3

AdamH
AdamH

Reputation: 2201

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.

Upvotes: 0

Related Questions