Simple Usage Examples
Complete Usage Example
package simple;
import org.yarnandtail.andhow.property.*;
public class HelloWorld {
// 1 Declare AndHow Properties
private static final StrProp NAME = StrProp.builder().defaultValue("Dave").build();
public static final IntProp REPEAT_COUNT = IntProp.builder().defaultValue(2).build();
public static void main(String[] args) {
// 2 Use AndHow Properties
for (int i = 0; i < REPEAT_COUNT.getValue(); i++) {
System.out.println("Hello, " + NAME.getValue());
}
}
}// 1 : Declare AndHow Properties
// 2 : Using AndHow Properties
Adding validation and command line arguments
// 1 : Declare AndHow Properties with validation
// 2 : Add command line arguments
Example with a database connection, aliases and exports
// 1 : Declare configuration Property's for this class
// 3 : Declare DB connection Properties
// 4 : Export Db properties to a java.util.Properties instance
Testing Applications with AndHow
// 1 : 'Kill' the current AndHow configuration
// 2 : Set a new configured value for TAX_RATE
// 3 : Cleanup after the test
Last updated