Java: which configuration framework to use?

2019-04-08 00:14发布

I need to decide which configuration framework to use. At the moment I am thinking between using properties files and XML files. My configuration needs to have some primitive grouping, e.g. in XML format would be something like:

<configuration>
    <group name="abc">
        <param1>value1</param1>
        <param2>value2</param2>
    </group>
    <group name="def">
        <param3>value3</param3>
        <param4>value4</param4>
    </group>
</configuration>

or a properties file (something similar to log4j.properties):

group.abc.param1 = value1 
group.abc.param2 = value2

group.def.param3 = value3
group.def.param4 = value4

I need bi-directional (read and write) configuration library/framework. Nice feature would be - that I could read out somehow different configuration groups as different objects, so I could later pass them to different places, e.g. - reading everything what belongs to group "abc" as one object and "def" as another. If that is not possible I can always split single configuration object into smaller ones myself in the application initialization part of course.

Which framework would best fit for me?

3条回答
乱世女痞
2楼-- · 2019-04-08 00:22

The simplest way to do this would be to use Simple XML. It can bind XML to Java POJOs in a very simple manner. Also, it is much faster than other such XML binding frameworks.

http://simple.sourceforge.net

Only 270K with no dependencies.

查看更多
仙女界的扛把子
3楼-- · 2019-04-08 00:27

Since you are saying that it is possible to also store objects in the config, I would suggest this:

http://commons.apache.org/configuration/

查看更多
一纸荒年 Trace。
4楼-- · 2019-04-08 00:28

Please take a look at this URL: http://issues.apache.org/jira/browse/CONFIGURATION-394

The Configuration framework which we're looking for it is something on top of Apache Commons Configuration and must support Concurrency Issues, JMX issues and most of stores(e.g .properties file, .xml files or PreferencesAPI).

What weblogic team provides on 'Administration Console' is intersting which through it you can have transactional(atomic) updates on configurations so that are registered listeners be notified.

The Apache guys insist that this project is out of scopes of Commons Configuration, maybe!

I've attached a simple configuration framework, take look please

查看更多
登录 后发表回答