AndHow!

Java application configuration

Configurable constants for Java application configuration

New Release: 1.5.0, October 10, 2020 - notes.

This release jumps from 0.4.2 to 1.5.0, reflecting that AndHow has been in production long enough to be considered production ready, and includes some API changes. This release removes deprecated methods, clarifies / subtly changes some behavior, and has general improvements and bug fixes. See the full release notes.

What if you could configure constants? What if Java application configuration was just constants?

AndHow configures your application with strongly typed Properties that work just like static final constants in your code. Values for Properties are loaded from multiple sources and are validated at startup.

Key Features

  • Strong Typing

  • Detailed validation

  • Simple to use and test

  • Use Java public & private modifiers to control Property value access

  • Validates all property values at startup to Fail Fast

  • Loads values from multiple sources (env. vars, system props, cmd line, prop files, JNDI, and more)

  • Generates configuration template files for the Properties in your application

Use it via Maven (available on Maven Central)

<dependency>
    <groupId>org.yarnandtail</groupId>
    <artifactId>andhow</artifactId>
    <version>1.5.0</version>
</dependency>

<dependency>
	<!-- Utils for unit testing apps using AndHow -->
	<groupId>org.yarnandtail</groupId>
	<artifactId>andhow-junit5-extensions</artifactId>
	<version>1.5.0</version>
	<scope>test</scope>
</dependency>

Declaring and Using AndHow Properties

Declaring Properties looks like this:

private static final StrProp HOST = StrProp.builder().startsWith("internal.").build();
public static final IntProp PORT = IntProp.builder().defaultValue(80).build();

Using Properties looks like this:

String theHost = HOST.getValue();
int thePort = PORT.getValue();

StrProp & IntProp are AndHow Propertys. Properties and their values are constants, so they are always declared as static final, but may be private or any scope. Properties may have default values, validation rules, description, and more.

Properties are used just like static final constants with .getValue() tacked on. They are strongly typed, so HOST.getValue() returns a String, PORT.getValue() returns an Integer.

At startup, AndHow scans System.Properties, environment variables, JNDI values, the andhow.properties file, etc., in a well established order. If the loaded value for any Property in the application does not meet the validation requirements, AndHow throws a detailed RuntimeException to fail fast and prevent the application from running with invalid configuration.

Where to next?

Live-Code Quickstart will get you started with AndHow right in the browser window.

&?!

Last updated