-
Notifications
You must be signed in to change notification settings - Fork 34
Home
Eric edited this page Mar 27, 2017
·
24 revisions
Strongly typed configuration with detailed validation that is simple to use for web apps, command line or any application environment.
- Strong Typing. Configuration Propertys are typed and only return that type. The getValue() method of the StrProp (String Property) returns a String. The getValue() method of an IntProp (Integer Property) returns an Integer.
- Detailed validation. Each Property can be required or optional. Strings can be matched to regex, bounds applied to numbers, etc..
- Load property values from nearly any property source, including property files, JNDI, command line, environmental variables and system properties.
- Simple construction via builders.
- Simple initial configuration via auto-generated sample files.
- Use configuration Properties in code just like Java constants, e.g.: MY_CONFIG_PROPERTY.getValue();
This eliminates a problematic aspect of most configuration strategies, which require
value keys buried in your source code, e.g.:
hashMap.get("HiddenMagicKey");
- Fail-Fast. Type conversion and validation are applied at startup, rather than at use.
- Managed session. A single application configuration initiation point is enforced. Race conditions or missing initiation fails rather than returning null for properties.
- Consolidated and structured application configuration API. Configuration Properties include a type, description, and validation rules. Properties can be grouped into logical sets with descriptions. Libraries/modules can present their entire configuration API as a PropertyGroup.
- Extensible value types and configuration sources. New types and sources of configuration (such as from a db) can be easily added.
- Clear error messages. Because Properties include metadata like name, description, type and validation rules, detailed error messages can be constructed.
- Support for legacy applications using System Properties.
Normally AndHow provides its own names for properties, however, it is also possible to use aliases.
An in alias provides a short name to read from a source, such as a property file or from command line.
An out alias provides an alternate name used to export the property.
A
GroupExport
annotation on aPropertyGroup
will direct AndHow to export property value to some other form - Currently exporting to SystemProperties is the only option supported, but that covers a lot of legacy code. For an example of this in use, see the NwisConfig Interface in this file. Note the use of theGroupExport
annotation and the aliases used on the properties in that group.
Note: The documentation in this wiki is out of date. Please see https://www.andhowconfig.org instead.