如何记录.properties文件? [英] How to document .properties files?

查看:88
本文介绍了如何记录.properties文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有记录.properties文件的标准方法?我具有Javadoc精神,可以在同一文件中拥有属性和文档,并且可以利用IDE集成吗?

Is there a standard way of documenting .properties files? Something in the spirit of Javadoc where I have properties and documentation in the same file and can leverage IDE integration?

这听起来很琐碎,但为说明我的问题,请考虑以下示例:假设我有一个Java应用程序,该应用程序由中央.properties文件控制,格式为

It might sound trivial but to illustrate my problem, consider the following example: Let's say I have a Java application which is controlled by a central .properties file in the format

key1=value1
key2=value2

要记录属性键的含义,我可以使用如下注释:

To document the meaning of property keys I could use comments like this:

# key1 does this and that
key1=value1

但是,如果我有多次应用的设置怎么办?

But what if I have settings that are applied more than once?

# key1 causes component1 to behave so and so
component1.key1=value1

# key1 causes component2 to behave so and so
component2.key1=value2

在上面,两个属性中key1的含义相同.但是,我不想重复该注释,因为我可能有数百个将key1属性应用到的组件.我可以像这样在开头使用单个注释:

In the above, the meaning of key1 is the same in both properties. However, I don't want to repeat the comment because I might have hundreds of components to which the key1 property is applied. I could use a single comment at the beginning like this:

# key1 causes the affected component to behave so and so
component1.key1=value1
component2.key1=value2
....

但是,如果我最后添加一个新组件,则每次都必须向上滚动以找到相关的文档注释.

But then if I add a new component at the end, I would have to scroll up every time to find the associated documentation comment.

我正在寻找一种定义属性模式含义的方法

I'm looking for a way to define the meaning of the property pattern

[COMPONENT].key1=value1

以一种我可以在IDE中轻松引用该文档的方式-就像您使用Java代码和Javadoc一样.

in a way that I can easily refer to that documentation in an IDE - just like you do with Java code and Javadoc.

推荐答案

如果您的配置是如此复杂,我会考虑使用Typesafe config

If your config is that complex I would consider using Typesafe config https://github.com/typesafehub/config/blob/master/README.md

这样做可以让您构造配置以使用json或hcon删除重复项.

Doing so would allow you to structure your config to remove duplication by using json or hcon.

完成此操作后,无论加载了什么配置,都应对其进行验证并报告所有问题.如果成功,则为该复杂配置构建一个过时的表示. Java中的Javabean,Scala中的案例类.

Having done that, whatever loads the config should validate it and report any issues. If successful, build an obect representation of this complex config. Javabean in Java, case classes in Scala.

记录加载配置的代码和代表配置的代码.

Document the code that loads the config and the code representing the config.

我在Scala项目中使用了这种方法,它避免了很多痛苦和混乱.

I've used this approach in Scala projects and it's saved a lot pain and confusion.

这篇关于如何记录.properties文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆