MCPcopy Index your code
hub / github.com/avaje/avaje-config

github.com/avaje/avaje-config @5.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release 5.2 ↗ · + Follow
663 symbols 2,244 edges 59 files 171 documented · 26%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Supported JVM Versions Discord Maven Central javadoc License Build native image build

Avaje Config

This library loads properties files that can be used to configure an application including "testing" and "local development" and dynamic configuration (changes to configuration properties at runtime).

<dependency>
  <groupId>io.avaje</groupId>
  <artifactId>avaje-config</artifactId>
  <version>${avaje.config.version}</version>
</dependency>

Typical use

  • Put application.yaml into src/main/resources for properties that have reasonable defaults
  • Put application-test.yaml into src/test/resources for properties used when running tests
  • Specify external properties via command line arguments. These effectively override application.yaml properties.

Config use

Getting property values


// get a String property
String value = Config.get("myapp.foo");

// with a default value
String value = Config.get("myapp.foo", "withDefaultValue");

// also int, long and boolean with and without default values
int intVal = Config.getInt("bar");
long longVal = Config.getLong("bar");
boolean booleanVal = Config.getBool("bar");

Register callback on property change.


Config.onChange("myapp.foo", newValue -> {
  // do something ...
});

Config.onChangeInt("myapp.foo", newIntValue -> {
  // do something ...
});

Config.onChangeLong("myapp.foo", newLongValue -> {
  // do something ...
});

Config.onChangeBool("myapp.foo", newBooleanValue -> {
  // do something ...
});

Loading properties

Config loads properties from expected locations as well as via command line arguments. Below is the how it looks for configuration properties.

  • loads from main resources (if they exist)

    • application.yaml
    • application.properties
  • loads files from the current working directory (if they exist)

    • application.yaml
    • application.properties
  • loads via system property props.file or environment variable PROPS_FILE (if defined)

  • loads via system property avaje.profiles or environment variable AVAJE_PROFILES (if defined).

Setting the config.profiles or environment variable CONFIG_PROFILES will cause avaje config to load the property files in the form application-${profile}.properties (will also work for yml/yaml files).

For example, if you set the config.profiles to dev,docker it will attempt to load application-dev.properties and application-docker.properties.

  • loads via load.properties property.

We can define a load.properties property which has name of property file in resource folder, or path locations for other properties/yaml files to load.

load.properties is pretty versatile and can even be chained. For example, in your main application properties, you can have load.properties=application-${profile:local}.properties to load based on another property, and in the loaded properties you can add load.properties there to load more properties, and so on.

Example application.properties:

common.property=value
load.properties=application-${profile:local}.properties,path/to/prop/application-extra2.properties
  • loads test resources (if they exist, nb: Test resources are only visible when running tests)
    • application-test.properties
    • application-test.yaml

If no test resources were loaded then it additionally loads from "local dev" and command line:

  • loads from "local dev".

We can specify an app.name property and then put a properties/yaml file at: ${user.home}/.localdev/{appName}.yaml We do this to set/override properties when we want to run the application locally (aka main method)

  • loads from command line arguments

Command line arguments starting with -P can specify properties/yaml files to load

When properties are loaded they are merged/overlayed.

config.load.systemProperties

If we set config.load.systemProperties to true then all the properties that have been loaded are then set into system properties.

Extension points exported contracts — how you extend this code

ConfigurationSource (Interface)
Additional source to load and update configuration. [4 implementers]
avaje-config/src/main/java/io/avaje/config/ConfigurationSource.java
AppConfigFetcher (Interface)
(no doc) [1 implementers]
avaje-aws-appconfig/src/main/java/io/avaje/config/appconfig/AppConfigFetcher.java
ConfigParser (Interface)
Load a config file into a flattened map. [4 implementers]
avaje-config/src/main/java/io/avaje/config/ConfigParser.java
ConfigurationPlugin (Interface)
Plugin that is initiated after the configuration has been loaded. [3 implementers]
avaje-config/src/main/java/io/avaje/config/ConfigurationPlugin.java
ModificationEventRunner (Interface)
Run the event listener notifications. Supply this using service loading to for example run the event listener notifi [3 …
avaje-config/src/main/java/io/avaje/config/ModificationEventRunner.java
ModificationEvent (Interface)
The event that occurs on configuration changes. Register to listen for these events via {@link Configuration#onChange(Co [2 …
avaje-config/src/main/java/io/avaje/config/ModificationEvent.java

Core symbols most depended-on inside this repo

get
called by 212
avaje-config/src/main/java/io/avaje/config/Configuration.java
setProperty
called by 67
avaje-config/src/main/java/io/avaje/config/Configuration.java
value
called by 66
avaje-config/src/main/java/io/avaje/config/Configuration.java
put
called by 38
avaje-config/src/main/java/io/avaje/config/ModificationEvent.java
log
called by 36
avaje-config/src/main/java/io/avaje/config/Configuration.java
add
called by 31
avaje-config/src/main/java/io/avaje/config/YamlLoaderSnake.java
of
called by 24
avaje-config/src/main/java/io/avaje/config/Configuration.java
set
called by 23
avaje-config/src/main/java/io/avaje/config/Configuration.java

Shape

Method 583
Class 56
Interface 19
Enum 5

Languages

Java100%

Modules by API surface

avaje-config/src/main/java/io/avaje/config/CoreConfiguration.java70 symbols
avaje-config/src/main/java/io/avaje/config/Configuration.java60 symbols
avaje-config/src/test/java/io/avaje/config/ConfigTest.java52 symbols
avaje-config/src/test/java/io/avaje/config/CoreConfigurationTest.java41 symbols
avaje-config/src/main/java/io/avaje/config/YamlLoaderSimple.java34 symbols
avaje-config/src/main/java/io/avaje/config/InitialLoader.java32 symbols
avaje-config/src/main/java/io/avaje/config/Config.java29 symbols
avaje-config/src/main/java/io/avaje/config/CoreEntry.java23 symbols
avaje-config/src/main/java/io/avaje/config/InitialLoadContext.java20 symbols
avaje-config/src/test/java/io/avaje/config/YamlParserTest.java19 symbols
avaje-config/src/main/java/io/avaje/config/CoreExpressionEval.java18 symbols
avaje-aws-appconfig/src/main/java/io/avaje/config/appconfig/AppConfigFetcher.java16 symbols

Datastores touched

myappDatabase · 1 repos
barDatabase · 1 repos

For agents

$ claude mcp add avaje-config \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact