AndHow! Java Configuration .
  • AndHow!
  • Live-Code Quickstart
  • Simple Usage Examples
  • User Guide
    • Key Concepts
    • AndHow Properties
    • Loaders & Load Order
    • Testing
    • AndHow Initialization
    • Configuring AndHow
    • Whitespace Handling
    • Integration and Exports
    • Changing the Load Order
    • Java9 and Above
    • Best Practices
  • Developer Guide
    • How to Contribute
    • First Checkout with Git
    • Project Branching Structure
    • New Workstation Setup
    • Background
    • Framework Testing
    • Conventions
    • Release Plan
    • HowTo Release
    • Troubleshooting
    • References
  • Help / Questions
  • Release Notes
    • Release 0.4.2
  • FAQs
  • Other
    • JUnit Extension Registration
Powered by GitBook
On this page
  • Configurable constants for Java application configuration
  • What if you could configure constants? What if Java application configuration was just constants?
  • Where to next?

Was this helpful?

AndHow!

Java application configuration

NextLive-Code Quickstart

Last updated 2 years ago

Was this helpful?

Configurable constants for Java application configuration

New Release: 1.5.0, October 10, 2020 - .

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.

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

  • 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.

Where to next?

&?!

Validates all property values at startup to

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

will get you started with AndHow right in the browser window.

Live-Code Quickstart
notes
release notes
Fail Fast
fail fast
well established order