开发者

Strongly Typed Configuration Sections for Java

In .NET you can create strongly-typed configuration sections using build-in base classes that do a lot of the mundane heavy lifting with respect to XML Serialization/De-serialization, schema validation, type-casting, etc...

I'm working on a Java application and I'm looking for a similar capability. If开发者_运维问答 there is a built-in facility for this I would prefer to not reinvent the wheel. I don't do a lot of Java so any guidance and links with examples/walk-throughs would be great.

Does anyone have any tips on how I can accomplish this using built-in Java capabilities?


I think the closest you can get to .NET configuration sections is the Preferences API.

This is still a rather low-level approach however. Its intended use is more geared towards user preferences than actual system-wide configuration.

Another option would be Commons Configuration, which provides similar functionality, still not strongly-typed.


If you're using Java 8, you can use https://github.com/backuity/p2s It is fail-fast and type-safe with almost no reflection (code is generated with an annotation processor, but plays well with IDE). Note that it is read-only.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜