开发者

Looking for cool java tool for loading config files [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 8 years ago.

开发者_StackOverflow中文版 Improve this question

I'm quite satisfied with the default solution, but is there anything more advanced?


Here's a nice way that allows you to override defaults per environment using spring:

property-placeholder location from another property


What are you looking for? properties is just alist of key/values pair.

You can go with more advanced proeprties like XML, but its more compilcated.


The Apache Commons-Configuration project has various implementations to read, write and manage configuration files. Among them are flat properties (key-value pairs in text files), structured XML (XML files with readable names for config parameters), hierarchical, Windows INI format, JNDI, System properties etc.

They support the basic data types (String, numbers, boolean), lists and converters for custom data types such as URLs, colors, dates etc.

Configurations can be read from various sources, such as files, input streams, in-memory representations, URLs, JDBC data sources, Property list files (plist), Strings, Applet parameters, Servlet parameters and of course System properties.

Unique features include XPath expression evaluation, variable interpolators, auto-reloading, observable configurations, validation and even multi-tenancy.

Example usage:

CompositeConfiguration config = new CompositeConfiguration();
config.addConfiguration(new SystemConfiguration());
config.addConfiguration(new PropertiesConfiguration("app.properties"));

// Some impls have special features:
// xmlConfig.setValidating(true);
// propsConfig.setAutoSave(true);
// propsConfig.setReloadingStrategy(new FileChangedReloadingStrategy());

config.setListDelimiter('/');
config.addProperty("greeting", "Hello, how are you?");
config.addProperty("colors.graph", "#808080/#00FFCC/#6422FF");

String salut = config.getString("greeting");
String[] colGraph = config.getStringArray("colors.graph");


Have a look at OWNER API, it is annotation based mini framework that does some neat things.

As per version 1.0.3 it does support object mapping (customizable by the user), automatic type conversion, variable expansion, loading properties from several sources with two different policies (merge files or take the first available), importing properties from maps (similar to the composite configuration of commons logging).

Version 1.0.4 will be released asap and it will include support for collections and arrays in type conversion, two flavors of "hot reload" with a notification mechanism (you change the file on disk and the object is automatically reload). All those features are available on the master branch already if you feel confortable to download the sources and package it by yourself.

And there are many more ideas I'm working on. If you have any requests, I'm happy to hear. See github issues for the other things that I'm working on.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜