### YAML Configuration Example Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/troubleshooting.md Example of correct YAML syntax for defining server properties with integer, boolean, and string types. ```yaml # Correct types server: port: 8080 # Integer ssl: true # Boolean name: "localhost" # String ``` -------------------------------- ### Example application-prod.yaml Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Configuration settings for the 'prod' environment, including logging level and application mode. ```yaml logging: level: INFO app: mode: prod ``` -------------------------------- ### YAML Property Example Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/troubleshooting.md Example of correct YAML syntax for defining server properties. ```yaml # CORRECT server: port: 8080 # NOT server_port or serverPort in YAML ``` -------------------------------- ### Example application-dev.yaml Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md A profile-specific configuration file for the 'dev' environment, overriding or adding settings. ```yaml logging: level: DEBUG ``` -------------------------------- ### Get Integer Properties with Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Shows how to get integer properties from the configuration, with an example including a default value. ```java // Integer properties int port = Config.getInt("server.port"); int maxConnections = Config.getInt("db.pool.size", 10); ``` -------------------------------- ### Example application.yaml Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Shows a sample application.yaml file defining server and application configurations, including external configuration loading. ```yaml # Server configuration server: port: 8080 host: 0.0.0.0 # Application configuration app: name: My Application mode: dev feature: enabled: true # External configuration load.properties: application-${app.mode}.yaml ``` -------------------------------- ### Explicit Profile Activation Example Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/profiles.md Demonstrates explicit activation for profiles other than the auto-loaded test profile, such as 'application-it.yaml'. ```bash java -Dconfig.profiles=it myapp.jar # loads application-it.yaml ``` -------------------------------- ### Get String Properties with Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Demonstrates how to retrieve string properties, including examples with and without default values. ```java // String properties String appName = Config.get("app.name"); String mode = Config.get("app.mode", "prod"); // with default ``` -------------------------------- ### Main Application Entry Point with Configuration Access Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md A complete Java application example demonstrating configuration loading, access, and listener registration. ```java import io.avaje.config.Config; import io.avaje.config.Configuration; public class MyApplication { private static final Configuration config = Config.asConfiguration(); public static void main(String[] args) { String appName = Config.get("app.name"); int port = Config.getInt("app.port", 8080); System.out.println("Starting " + appName); // Register listeners for dynamic updates Config.onChangeBool("features.new-ui", enabled -> { System.out.println("New UI feature: " + enabled); }); startApplication(); } private static void startApplication() { boolean analyticsEnabled = Config.getBool("features.analytics", true); System.out.println("Analytics enabled: " + analyticsEnabled); } } ``` -------------------------------- ### Minimal Avaje Config Usage Example Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Demonstrates basic property retrieval with and without default values, and setting up change listeners for specific properties. ```java // Get properties String appName = Config.get("app.name"); int port = Config.getInt("server.port", 8080); // with default boolean enabled = Config.getBool("feature.enabled", true); // Listen for changes Config.onChange("server.port", newPort -> { System.out.println("Port changed to: " + newPort); }); Config.onChangeInt("request.timeout", newTimeout -> { updateTimeout(newTimeout); }); ``` -------------------------------- ### Dynamic Feature Flag Example Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/change-listeners.md A practical example demonstrating how to use `Config.onChangeBool()` to dynamically update a feature flag. The listener updates a volatile boolean field, ensuring thread-safe access. ```java @Singleton public class FeatureManager { private volatile boolean featureEnabled; @Inject public FeatureManager() { this.featureEnabled = Config.getBool("features.new-ui", false); Config.onChangeBool("features.new-ui", newValue -> { this.featureEnabled = newValue; System.out.println("Feature toggle updated: " + newValue); }); } public boolean isEnabled() { return featureEnabled; } } ``` -------------------------------- ### Default Application Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Example of a default application.yaml file, including AWS AppConfig settings and feature flags. ```yaml app: name: MyService version: 1.0 aws.appconfig: application: my-service-config environment: ${ENVIRONMENT:dev} configuration: default pollingSeconds: 45 features: new-ui: false analytics: true ``` -------------------------------- ### Database Service Configuration Example Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Illustrates using the Configuration object to retrieve database connection properties like URL, username, and pool size. ```java public class DatabaseService { private final Configuration config; public DatabaseService() { this.config = Config.asConfiguration(); } public void setupConnection() { String url = config.get("database.url"); String user = config.get("database.username"); int poolSize = config.getInt("database.max-pool-size", 10); System.out.println("Connecting to: " + url); System.out.println("User: " + user); System.out.println("Pool size: " + poolSize); } } ``` -------------------------------- ### Get Boolean Properties with Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Provides examples for retrieving boolean configuration values, including a default value. ```java // Boolean properties boolean enabled = Config.getBool("feature.enabled"); boolean debug = Config.getBool("logging.debug", false); ``` -------------------------------- ### Build and Test Native Image Locally Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/native-image.md Install GraalVM, build the native image locally using Maven, and then test its execution. ```bash # Install GraalVM sdk install java 21-graal # Build native image locally mvn -Pnative clean package # Test ./target/myapp ``` -------------------------------- ### Load Properties with Chained Load Files Source: https://github.com/avaje/avaje-config/blob/main/README.md Example of an application.properties file demonstrating how to load additional properties files, including dynamic loading based on profiles and paths. ```properties common.property=value load.properties=application-${profile:local}.properties,path/to/prop/application-extra2.properties ``` -------------------------------- ### Example Production Profile Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/profiles.md Configuration tailored for the production environment. Includes settings like SSL enablement and production database host, differing from development settings. ```yaml server: port: 443 ssl: enabled: true database: host: db.example.com port: 5432 logging: level: WARN ``` -------------------------------- ### Example Development Profile Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/profiles.md Configuration specific to the development environment. Overrides or adds settings relevant for local development, such as server port and database host. ```yaml server: port: 8080 database: host: localhost port: 5432 logging: level: DEBUG ``` -------------------------------- ### Example Shared Default Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/profiles.md Defines the default application settings that are shared across all environments. This file serves as the base for other profile-specific configurations. ```yaml app: name: MyApp version: 1.0.0 logging: level: INFO ``` -------------------------------- ### Configuration Files with Property Interpolation Example Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Illustrates using property interpolation within YAML configuration files to reference other defined properties and load external files. ```yaml # Define reusable values db: host: localhost port: 5432 name: myapp # Reference them database: url: jdbc:postgresql://${db.host}:${db.port}/${db.name} poolSize: 20 # Load additional files load.properties: application-${app.mode}.yaml ``` -------------------------------- ### Load Application Startup Configuration (Java) Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Load essential configuration properties like application name, server port, and debug mode when the application starts. Uses default values if properties are not found. ```java public class Application { public static void main(String[] args) { String appName = Config.get("app.name"); int port = Config.getInt("server.port", 8080); boolean debug = Config.getBool("logging.debug", false); System.out.println("Starting " + appName + " on port " + port); startServer(port, debug); } } ``` -------------------------------- ### Test Configuration (YAML) Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Create src/test/resources/application-test.yaml to override settings specifically for testing environments. This example shows modified port, debug, and database settings. ```yaml # Override settings for testing app: port: 8081 debug: true database: url: jdbc:h2:mem:test username: sa max-pool-size: 2 features: logging-enabled: false ``` -------------------------------- ### Properties Format in AWS AppConfig Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Example of configuration structure stored in Properties format within AWS AppConfig. ```properties service.name=PaymentService service.max-retries=3 service.timeout-seconds=30 features.new-checkout=true features.advanced-analytics=false database.pool-size=20 ``` -------------------------------- ### Docker Compose Environment Variables Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/cloud-integration.md Example Docker Compose file demonstrating how to set environment variables for application configuration, including database and Redis connection details. ```yaml version: '3' services: app: image: myapp:latest environment: - DATABASE_HOST=postgres - DATABASE_PORT=5432 - DATABASE_USER=myuser - DATABASE_PASSWORD=mypassword - REDIS_HOST=redis - REDIS_PORT=6379 depends_on: - postgres - redis postgres: image: postgres:14 environment: - POSTGRES_USER=myuser - POSTGRES_PASSWORD=mypassword - POSTGRES_DB=myapp redis: image: redis:7 ``` -------------------------------- ### Get String Property Source: https://github.com/avaje/avaje-config/blob/main/README.md Retrieve a String property value from the configuration. A default value can be provided if the property is not found. ```java String value = Config.get("myapp.foo"); ``` ```java String value = Config.get("myapp.foo", "withDefaultValue"); ``` -------------------------------- ### YAML Format in AWS AppConfig Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Example of configuration structure stored in YAML format within AWS AppConfig. ```yaml service: name: PaymentService max-retries: 3 timeout-seconds: 30 features: new-checkout: true advanced-analytics: false database: pool-size: 20 ``` -------------------------------- ### Get String Property - Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Retrieve a string property from the configuration. Use this when the expected value is a string. ```java String value = Config.get("app.name"); ``` -------------------------------- ### Obtain Configuration Object Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Get the underlying Configuration object from Config.asConfiguration(). This is useful for passing configuration as a parameter or storing it as an instance variable. ```java import io.avaje.config.Config; import io.avaje.config.Configuration; Configuration configuration = Config.asConfiguration(); ``` -------------------------------- ### Mount ConfigMap and Secret in Kubernetes Pod Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/cloud-integration.md Example Kubernetes Pod definition showing how to mount a ConfigMap and a Secret to provide configuration and sensitive data to the application container using envFrom. ```yaml apiVersion: v1 kind: Pod metadata: name: myapp spec: containers: - name: app image: myapp:latest envFrom: - configMapRef: name: myapp-config - secretRef: name: myapp-secrets ``` -------------------------------- ### Get Integer Property - Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Retrieve an integer property from the configuration. Use this for numeric values expected to be integers. ```java int port = Config.getInt("server.port"); ``` -------------------------------- ### Get Long Properties with Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Illustrates retrieving long integer properties, including a case with a specified default value. ```java // Long properties long timeout = Config.getLong("request.timeout"); long maxSize = Config.getLong("upload.max.bytes", 10485760L); ``` -------------------------------- ### Kubernetes ConfigMap for Application Settings Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/cloud-integration.md Example Kubernetes ConfigMap to store non-sensitive application configuration data, such as server port and application name. ```yaml apiVersion: v1 kind: ConfigMap metadata: name: myapp-config data: application.yaml: | server: port: 8080 app: name: MyApp ``` -------------------------------- ### avaje-config Properties Example Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/spring-boot.md Define configuration properties in `application.yaml`, including environment variable overrides and AWS AppConfig settings. This file is loaded by avaje-config independently of Spring Boot. ```yaml db: url: ${DB_URL:jdbc:postgresql://localhost:5432/mydb} user: ${DB_USER:myuser} pass: ${DB_PASS:} aws.appconfig: enabled: true application: ${ENVIRONMENT_NAME:dev}-my-service environment: ${ENVIRONMENT_NAME:dev} configuration: default ``` -------------------------------- ### Get Integer Configuration Value Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Retrieve an Integer configuration property using Config.getInt(). The overloaded version accepts a default value. ```java public class AppConfig { public static int getPort() { // Get integer value return Config.getInt("app.port"); } public static int getPort(int defaultPort) { // Get integer with default return Config.getInt("app.port", defaultPort); } public static int getMaxPoolSize() { return Config.getInt("database.max-pool-size", 5); } } ``` -------------------------------- ### Get String Configuration Value Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Retrieve a String configuration property using Config.get(). An exception is thrown if the property is not found. Use the overloaded version with a default value to avoid exceptions. ```java import io.avaje.config.Config; public class AppConfig { public static String getAppName() { // Get value, throws exception if not found return Config.get("app.name"); } public static String getAppName(String defaultName) { // Get value with default if not found return Config.get("app.name", defaultName); } public static String getDatabaseUrl() { return Config.get("database.url", "jdbc:h2:mem:default"); } } ``` -------------------------------- ### AWS AppConfig Configuration in application.yaml Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Configure AWS AppConfig settings within your application.yaml file. This example shows how to enable AppConfig, specify the application and environment, and demonstrates how test configurations can disable it. ```yaml # src/main/resources/application.yaml - Production aws.appconfig: enabled: true application: my-app environment: prod # src/test/resources/application-test.yaml - Tests only aws.appconfig: enabled: false ``` -------------------------------- ### Feature Flags using AWS AppConfig Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Define and access feature flags using the avaje-config API. This example shows how to check if a feature, like 'new checkout', is enabled. ```java public class FeatureFlags { public static boolean isNewCheckoutEnabled() { return Config.enabled("features.checkout.new", false); } public static boolean isAdvancedSearchEnabled() { return Config.enabled("features.search.advanced", false); } } // Usage in code if (FeatureFlags.isNewCheckoutEnabled()) { useNewCheckoutFlow(); } else { useOldCheckoutFlow(); } ``` -------------------------------- ### Automatic Environment Variable Override Example Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/environment-variables.md Shows how environment variables can automatically override configuration file values without explicit syntax in YAML. The `DATABASE_HOST` environment variable will override the `database.host` property. ```yaml # application.yaml - no ${...} needed database: host: localhost port: 5432 ``` ```bash # This env var automatically overrides database.host → DATABASE_HOST export DATABASE_HOST=prod-db.example.com java myapp.jar ``` -------------------------------- ### Configure Logging Levels in Properties Source: https://github.com/avaje/avaje-config/blob/main/avaje-dynamic-logback/README.md Use 'log.level.' as a prefix in properties configuration to set logging levels for specific packages or classes. This configuration is applied when the application starts and whenever the configuration is updated. ```properties log.level.com.example=INFO log.level.com.example.sample=TRACE ``` -------------------------------- ### Get String Property with Default Value - Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Retrieve a string property, falling back to a default value if the property is not found. Useful for optional settings. ```java String mode = Config.get("app.mode", "prod"); ``` -------------------------------- ### Configure Logging Levels in YAML Source: https://github.com/avaje/avaje-config/blob/main/avaje-dynamic-logback/README.md Use 'log.level.' as a prefix in YAML configuration to set logging levels for specific packages or classes. This configuration is applied when the application starts and whenever the configuration is updated. ```yaml log.level: com.example: INFO com.example.sample: TRACE ``` -------------------------------- ### Build and Run Native Image Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/native-image.md Use Maven to build the native executable and then run it. ```bash # Build the native executable mvn -Pnative clean package # Run the native image ./target/myapp ``` -------------------------------- ### Get Boolean Property - Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Retrieve a boolean property from the configuration. Use this for flag-based settings. ```java boolean enabled = Config.getBool("feature.enabled"); ``` -------------------------------- ### Get Long Configuration Value Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Retrieve a Long configuration property using Config.getLong(). A default value can be provided. ```java public class AppConfig { public static long getTimeoutMillis() { // Get long value return Config.getLong("app.timeout-millis", 30000L); } } ``` -------------------------------- ### Constructor Injection Pattern for Services Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Shows how to use configuration properties to initialize a service class, such as setting up a database connection pool with URL and size. ```java public class DatabaseConnectionPool { private final String url; private final int maxSize; public DatabaseConnectionPool() { this.url = io.avaje.config.Config.get("database.url"); this.maxSize = io.avaje.config.Config.getInt("database.max-pool-size", 10); } public void initialize() { // Set up connection pool } } ``` -------------------------------- ### Define Application Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/getting-started.md Create an application.yaml file in src/main/resources to define your application's configuration settings. ```yaml server: port: 8080 ssl: enabled: false database: host: localhost port: 5432 name: myapp ``` -------------------------------- ### Get Boolean Configuration Value Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Retrieve a Boolean configuration property using Config.getBool(). The method accepts a default value. ```java public class AppConfig { public static boolean isDebugEnabled() { // Get boolean value return Config.getBool("app.debug"); } public static boolean isLoggingEnabled() { return Config.getBool("features.logging-enabled", true); } } ``` -------------------------------- ### Get Numeric and Boolean Properties Source: https://github.com/avaje/avaje-config/blob/main/README.md Retrieve integer, long, and boolean property values. Default values can also be specified for these types. ```java int intVal = Config.getInt("bar"); ``` ```java long longVal = Config.getLong("bar"); ``` ```java boolean booleanVal = Config.getBool("bar"); ``` -------------------------------- ### Main Application Configuration (Properties) Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Alternatively, define production configuration using src/main/resources/application.properties. This format is equivalent to the YAML version. ```properties app.name=MyApplication app.version=1.0.0 app.port=8080 app.timeout-seconds=30 app.debug=false database.url=jdbc:postgresql://localhost:5432/myapp database.username=appuser database.max-pool-size=10 features.logging-enabled=true ``` -------------------------------- ### Unit Testing with Custom Config (Java) Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Set system properties to simulate custom configuration for unit tests. Verifies that configuration values are loaded correctly. ```java @Test void testWithCustomConfig() { // Set system property before test System.setProperty("app.mode", "test"); System.setProperty("server.port", "9999"); String mode = Config.get("app.mode"); int port = Config.getInt("server.port"); assertEquals("test", mode); assertEquals(9999, port); } ``` -------------------------------- ### Access Configuration Properties in Java Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Demonstrates accessing string, integer, long, and boolean configuration values with default fallbacks using the Configuration object. ```java public class AppService { private final Configuration configuration; public AppService() { this.configuration = Config.asConfiguration(); } public void initialize() { // Get string values String appName = configuration.get("app.name"); String appName = configuration.get("app.name", "DefaultApp"); // Get integer values int port = configuration.getInt("app.port"); int port = configuration.getInt("app.port", 8080); // Get long values long timeout = configuration.getLong("app.timeout-millis", 30000L); // Get boolean values boolean debug = configuration.getBool("app.debug"); boolean debug = configuration.getBool("app.debug", false); } } ``` -------------------------------- ### Activate Profile via System Property Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/profiles.md Activate a specific profile by setting the 'config.profiles' system property when running your application. Multiple profiles can be activated by comma-separating them. ```bash java -Dconfig.profiles=dev myapp.jar ``` ```bash java -Dconfig.profiles=test myapp.jar ``` ```bash java -Dconfig.profiles=prod myapp.jar ``` ```bash java -Dconfig.profiles=prod,docker myapp.jar ``` -------------------------------- ### Kubernetes Secret for Sensitive Data Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/cloud-integration.md Example Kubernetes Secret to securely store sensitive information like database passwords and API keys. ```yaml apiVersion: v1 kind: Secret metadata: name: myapp-secrets type: Opaque stringData: DATABASE_PASSWORD: secretpassword API_KEY: secretkey ``` -------------------------------- ### Main Application Configuration (YAML) Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Define production configuration using src/main/resources/application.yaml. This file sets default values for application, database, and feature flags. ```yaml # Application configuration app: name: MyApplication version: 1.0.0 port: 8080 timeout-seconds: 30 debug: false # Database configuration database: url: jdbc:postgresql://localhost:5432/myapp username: appuser max-pool-size: 10 # Feature flags features: logging-enabled: true ``` -------------------------------- ### Provide Default Values Directly Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/default-values.md Use this approach for simple, single properties where you need a fallback value if the property is not explicitly set. Imports for `io.avaje.config.Config` are required. ```java import io.avaje.config.Config; // Returns 8080 if not configured int port = Config.getInt("server.port", 8080); // Returns "localhost" if not configured String host = Config.get("server.host", "localhost"); // Returns false if not configured boolean ssl = Config.getBool("server.ssl.enabled", false); ``` -------------------------------- ### Get Long Property - Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Retrieve a long property from the configuration. Use this for numeric values that may exceed the range of an integer. ```java long timeout = Config.getLong("request.timeout"); ``` -------------------------------- ### Basic Configuration Test Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/testing.md Verify that test configuration values from `application-test.yaml` are automatically loaded and accessible. No explicit profile activation is needed for `application-test.yaml`. ```java @Test public void testConfiguration() { // application-test.yaml values are available automatically String dbHost = Config.get("database.host"); assertEquals("localhost", dbHost); } ``` -------------------------------- ### Activate Profile via Environment Variable Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/profiles.md Activate a profile by setting the CONFIG_PROFILES environment variable before running your application. This is an alternative to using system properties. ```bash export CONFIG_PROFILES=prod java myapp.jar ``` -------------------------------- ### Listen for String Property Changes Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Sets up a listener to react to changes in a specific string configuration property. ```java // Listen for string property changes Config.onChange("server.port", newPort -> { System.out.println("Port changed to: " + newPort); }); ``` -------------------------------- ### Access Configuration in Service Class Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Demonstrates retrieving database configuration properties within a service class constructor using static Config methods. ```java public class DatabaseService { private final String dbUrl; private final String dbUser; private final int maxPoolSize; public DatabaseService() { this.dbUrl = Config.get("database.url"); this.dbUser = Config.get("database.username"); this.maxPoolSize = Config.getInt("database.max-pool-size", 10); } public void connect() { System.out.println("Connecting to " + dbUrl); // Initialize connection pool with maxPoolSize } } ``` -------------------------------- ### Avaje Configuration Directory Structure Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Standard project structure for Avaje configuration files. Main configuration resides in `src/main/resources`, while test-specific overrides are in `src/test/resources`. ```text src/ ├── main/ │ └── resources/ │ ├── application.yaml # Main configuration (production defaults) │ └── application.properties # Alternative format for main config └── test/ └── resources/ ├── application-test.yaml # Test configuration overrides └── application-test.properties # Alternative format for test config ``` -------------------------------- ### Load Profile-Specific Configuration (Bash) Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Load profile-specific configuration files by setting the CONFIG_PROFILES environment variable. This allows for different configurations based on the environment (e.g., dev, docker). ```bash export CONFIG_PROFILES=dev,docker java MyApp ``` -------------------------------- ### Access Configuration in Main Application Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Shows how to access application properties like name, port, and debug mode directly in the main method using static Config methods. ```java public class MyApplication { public static void main(String[] args) { String appName = Config.get("app.name", "MyApp"); int port = Config.getInt("app.port", 8080); boolean debug = Config.getBool("app.debug", false); System.out.println("Starting " + appName + " on port " + port); if (debug) { System.out.println("Debug mode enabled"); } } } ``` -------------------------------- ### Build Native Image with AWS AppConfig Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Build your GraalVM native image using Maven. This process automatically includes application configuration files and loads AWS AppConfig configuration at startup. ```bash mvn clean package -Pnative ``` -------------------------------- ### Listen to Any Configuration Change Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/change-listeners.md Omit the key arguments in `Config.onChange()` to register a listener that fires for any configuration change. The listener receives a `ModificationEvent` with all modified keys. ```java Config.onChange(event -> { System.out.println("Any config changed: " + event.modifiedKeys()); }); ``` -------------------------------- ### Load and Access Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/getting-started.md Access configuration values programmatically using Config.getInt(), Config.get(), and Config.getBool(). Provide default values for boolean types. ```java import io.avaje.config.Config; public class MyApplication { public static void main(String[] args) { int serverPort = Config.getInt("server.port"); String dbHost = Config.get("database.host"); boolean sslEnabled = Config.getBool("server.ssl.enabled", false); } } ``` -------------------------------- ### Accessing Overridden Configuration Value in Java Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/environment-variables.md Illustrates how to retrieve a configuration value in Java after it has been potentially overridden by an environment variable. The `Config.get` method will return the value from the environment variable if set. ```java // Still returns "prod-db.example.com" from env var String host = Config.get("database.host"); ``` -------------------------------- ### Increase AWS AppConfig Polling Interval Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Adjust the polling interval for AWS AppConfig to prevent performance issues caused by frequent polling. This example sets the polling interval to 2 minutes. ```yaml aws.appconfig: pollingSeconds: 120 # Poll every 2 minutes instead of 45 seconds refreshSeconds: 119 ``` -------------------------------- ### Register Custom Resource Files for Native Image Source: https://github.com/avaje/avaje-config/blob/main/graalvm-native-image.md If using non-standard configuration file names, register them in a 'resource-config.json' file within the native-image configuration directory to ensure they are included in the native executable. ```json { "resources": [ { "pattern": "my-service.*yaml" } ] } ``` -------------------------------- ### Test Configuration File Structure Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/testing.md Organize test-specific configuration files within the `src/test/resources` directory. This includes default test configurations, profile-specific overrides, and integration test configurations. ```yaml src/test/resources/ ├── application.yaml # Test defaults ├── application-test.yaml # Profile-specific └── application-it.yaml # Integration test config ``` ```yaml server: port: 0 # Use random port database: host: localhost port: 5432 cache: enabled: false ``` -------------------------------- ### Integration Testing with Default Config (Java) Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Load configuration from default sources like application.yaml during integration tests. Asserts that essential properties are present and valid. ```java @Test void testConfigIntegration() { // Load from application.yaml String appName = Config.get("app.name"); int port = Config.getInt("server.port", 8080); assertNotNull(appName); assertTrue(port > 0); } ``` -------------------------------- ### Caching Configuration Values and Using @Config Classes Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/troubleshooting.md Optimize performance by caching frequently accessed configuration values or by using `@Config` classes, which are loaded only once. ```java // Cache the value private static final int CACHE_TTL = Config.getInt("cache.ttl", 300); // Or use @Config class (loaded once) @Config public class CacheConfig { public final int ttl; public CacheConfig(int ttl) { this.ttl = ttl; } } ``` -------------------------------- ### Listen for Integer Property Changes Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Configures a callback to be executed when an integer configuration property is updated. ```java // Listen for integer changes Config.onChangeInt("request.timeout", newTimeout -> { requestHandler.setTimeout(newTimeout); }); ``` -------------------------------- ### Configuration Wrapper Class Pattern Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md Provides a static utility class to centralize access to application configuration properties, offering default values for convenience. ```java public class Config { public static String appName() { return io.avaje.config.Config.get("app.name", "MyApplication"); } public static int port() { return io.avaje.config.Config.getInt("app.port", 8080); } public static String databaseUrl() { return io.avaje.config.Config.get("database.url"); } public static int maxPoolSize() { return io.avaje.config.Config.getInt("database.max-pool-size", 10); } } // Usage: int port = Config.port(); String dbUrl = Config.databaseUrl(); ``` -------------------------------- ### Set Environment at Runtime for Native Executable Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Pass the desired environment as a system property when running the native executable. This allows you to specify the runtime environment, such as 'prod'. ```bash ./target/my-app -DENVIRONMENT=prod ``` -------------------------------- ### Setting Environment Variables for Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/troubleshooting.md Set environment variables before running the application to be used for configuration property replacement. ```bash # Set the environment variable export DATABASE_HOST=prod-db.example.com export DATABASE_PORT=5432 java myapp.jar ``` -------------------------------- ### Define Defaults in Configuration Classes Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/default-values.md Utilize constructor parameters with default values for multiple related properties, ensuring type safety. The `@Config` and `@ConfigProperty` annotations are necessary. ```java @Config public class AppConfig { public final int serverPort; public final String serverHost; public final boolean sslEnabled; public AppConfig( @ConfigProperty(value = "server.port", defValue = "8080") int serverPort, @ConfigProperty(value = "server.host", defValue = "localhost") String serverHost, @ConfigProperty(value = "server.ssl.enabled", defValue = "false") boolean sslEnabled ) { this.serverPort = serverPort; this.serverHost = serverHost; this.sslEnabled = sslEnabled; } } ``` -------------------------------- ### Configuration Access Methods Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md These methods allow you to retrieve configuration properties as different data types. You can also provide a default value to be returned if the property is not found. ```APIDOC ## Configuration Access ### Description Access configuration properties by key, with support for various data types and default values. ### Methods - `Config.get(key)`: Get string property. - `Config.getInt(key)`: Get integer property. - `Config.getLong(key)`: Get long property. - `Config.getBool(key)`: Get boolean property. - `Config.get(key, defaultValue)`: Get string property with a default value. ### Examples ```java // Get a string property String appName = Config.get("app.name"); // Get an integer property int port = Config.getInt("server.port"); // Get a boolean property with a default value boolean enabled = Config.getBool("feature.enabled", true); ``` ``` -------------------------------- ### Listen for Long Property Changes Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Demonstrates how to register a listener for changes in a long integer configuration property. ```java // Listen for long changes Config.onChangeLong("upload.max.bytes", newSize -> { fileService.setMaxSize(newSize); }); ``` -------------------------------- ### Accessing Active Profile in Code Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/profiles.md Retrieve the currently active configuration profile using Config.get(). This allows for conditional logic based on the active environment. ```java String profile = Config.get("config.profiles", "dev"); if (profile.equals("prod")) { // Production-specific behavior } ``` -------------------------------- ### Dynamic Configuration Updates with `Config.onChange()` Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/spring-boot.md Listen for changes in configuration values, such as feature flags from AWS AppConfig, using `Config.onChange()` to update application state at runtime. ```java @Component class FeatureFlags { private volatile boolean newUiEnabled; @PostConstruct void init() { this.newUiEnabled = Config.getBool("features.new-ui", false); Config.onChangeBool("features.new-ui", enabled -> { this.newUiEnabled = enabled; }); } public boolean isNewUiEnabled() { return newUiEnabled; } } ``` -------------------------------- ### Accessing Configuration Properties with Type Matching Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/troubleshooting.md Access configuration properties ensuring the type matches the expected getter method. Mismatched types will result in errors. ```java // Matching types int port = Config.getInt("server.port"); // OK boolean ssl = Config.getBool("server.ssl"); // OK String name = Config.get("server.name"); // OK // Type mismatch - these will fail: // int port = Config.getInt("server.name"); // NO - wrong type // boolean ssl = Config.getBool("server.port"); // NO - wrong type ``` -------------------------------- ### Specify Defaults in YAML Configuration Files Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/default-values.md Define default values within your `application.yaml` file. This is useful for defaults that are shared across different environments. ```yaml server: port: 8080 host: localhost ssl: enabled: false keystore: classpath:keystore.jks database: connections: 10 timeout: 30 ``` -------------------------------- ### AWS AppConfig Configuration with Properties Format Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Configure AWS AppConfig settings using the properties format in application.properties. ```properties aws.appconfig.enabled=true aws.appconfig.application=my-application aws.appconfig.environment=${ENVIRONMENT:dev} aws.appconfig.configuration=default aws.appconfig.pollingEnabled=true aws.appconfig.pollingSeconds=45 ``` -------------------------------- ### Dynamic Service Configuration with Avaje-Config Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Manage dynamic service configurations like pool size and timeouts. This class retrieves integer configuration values and provides a method to watch for changes. ```java public class ServiceConfig { private final Configuration config; public ServiceConfig() { this.config = Config.asConfiguration(); } public int getMaxPoolSize() { return config.getInt("service.pool-size", 10); } public int getTimeoutSeconds() { return config.getInt("service.timeout-seconds", 30); } public void watchMaxPoolSize(IntConsumer listener) { config.onChangeInt("service.pool-size", listener); } } ``` -------------------------------- ### Checking Active Profiles Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/troubleshooting.md Retrieve the currently active configuration profiles. Defaults to 'dev' if not explicitly set. ```java String profiles = Config.get("config.profiles", "dev"); System.out.println("Active profiles: " + profiles); ``` -------------------------------- ### Automatic Loading of Test Profile Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/profiles.md The 'application-test.yaml' file in 'src/test/resources' is automatically loaded by avaje-config during test runs without explicit profile activation. ```text src/test/resources/ └── application-test.yaml ← loaded automatically, no profile activation needed ``` -------------------------------- ### Activate Profile in Native Executable Source: https://github.com/avaje/avaje-config/blob/main/graalvm-native-image.md Activate a specific profile when running a GraalVM native executable by setting the 'avaje.profiles' system property. ```shell ./target/my-app -Davaje.profiles=prod ``` -------------------------------- ### Registering and Debugging Config Listeners Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/troubleshooting.md Register a callback to be notified when configuration changes. Use `reloadSources()` to manually trigger change detection. ```java Config.onChange(event -> { System.out.println("Config changed: " + event.modifiedKeys()); }); // Force reload of all configuration sources Config.asConfiguration().reloadSources(); ``` -------------------------------- ### Testing with Test Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md This test automatically uses `application-test.yaml` or `application-test.properties`. Ensure the test configuration file is present in `src/test/resources` for overrides. ```java import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import io.avaje.config.Config; public class ConfigurationTest { @Test public void testWithTestConfiguration() { // This test automatically uses application-test.yaml // Port will be 8081 (from test config) int port = Config.getInt("app.port"); assertEquals(8081, port); } } ``` -------------------------------- ### Access Environment Variables with Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/environment-variables.md Read environment variables directly using Config.get() and Config.getInt(). These methods automatically map configuration keys to environment variable names (e.g., 'database.host' to 'DATABASE_HOST'). ```java import io.avaje.config.Config; String dbHost = Config.get("database.host"); // Uses ${DATABASE_HOST} int port = Config.getInt("server.port"); // Uses ${SERVER_PORT} ``` -------------------------------- ### Test Configuration Change Listener Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/testing.md Register a listener with `Config.onChange()` to react to changes in configuration properties. Ensure to trigger a configuration reload after modifying properties. ```java @Test public void testConfigChangeListener() { List changedKeys = new ArrayList<>(); Config.onChange(event -> { changedKeys.addAll(event.modifiedKeys()); }, "server.port"); System.setProperty("server.port", "9000"); // Trigger reload of all configuration sources Config.asConfiguration().reloadSources(); assertTrue(changedKeys.contains("server.port")); } ``` -------------------------------- ### Runtime Configuration Updates (Java) Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Dynamically update configuration values, such as feature flags, without restarting the application. Listen for changes and update application state accordingly. ```java @Singleton public class FeatureManager { private boolean featureEnabled; @Inject public FeatureManager() { this.featureEnabled = Config.getBool("features.new-ui", false); // Listen for changes and update dynamically Config.onChangeBool("features.new-ui", newValue -> { this.featureEnabled = newValue; System.out.println("Feature toggle updated: " + newValue); }); } public boolean isEnabled() { return featureEnabled; } } ``` -------------------------------- ### Test Typed Configuration Change Listener Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/testing.md Use `Config.onChangeInt()` for listeners that specifically track changes to integer-typed configuration properties. This provides type-safe callbacks. ```java Config.onChangeInt("server.port", newPort -> { System.out.println("Port changed to: " + newPort); }); ``` -------------------------------- ### Override Configuration with Environment Variables (Bash) Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Override configuration properties using environment variables. This is an alternative to command-line arguments for setting configuration values. ```bash export SERVER_PORT=9000 export APP_NAME="Custom Name" java MyApp ``` -------------------------------- ### Test Configuration (Properties) Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/adding-avaje-config.md An alternative to the YAML test configuration, using the properties format for src/test/resources/application-test.properties. This provides test-specific overrides. ```properties app.port=8081 app.debug=true database.url=jdbc:h2:mem:test database.username=sa database.max-pool-size=2 features.logging-enabled=false ``` -------------------------------- ### Override Configuration with Command-Line Arguments (Bash) Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Override configuration properties by setting system properties directly on the Java command line. This provides the highest priority for configuration values. ```bash java -Dapp.name="Custom Name" -Dserver.port=9000 MyApp ``` -------------------------------- ### Integration Test Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/testing.md Define configuration for integration tests in `application-it.yaml`. This file is loaded explicitly when needed, typically for testing against external services. ```yaml server: port: 8080 database: host: localhost port: 5432 name: test_db redis: host: localhost port: 6379 ``` -------------------------------- ### Basic AWS AppConfig Configuration in application.yaml Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Configure AWS AppConfig settings in your application.yaml file for basic integration. Ensure AWS credentials are available. ```yaml aws.appconfig: enabled: true application: my-application environment: ${ENVIRONMENT:dev} configuration: default ``` -------------------------------- ### Configuration Wrapper with Change Tracking Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Implement a configuration wrapper that updates a volatile variable when a specific configuration value changes in AWS AppConfig. It also logs a message when the configuration is updated. ```java public class DynamicConfig { private volatile int maxRetries; public DynamicConfig() { this.maxRetries = Config.getInt("service.max-retries", 3); // Update when AWS AppConfig changes Config.onChangeInt("service.max-retries", newValue -> { this.maxRetries = newValue; onConfigChanged(); }); } public int getMaxRetries() { return maxRetries; } private void onConfigChanged() { System.out.println("Configuration updated from AWS AppConfig"); } } ``` -------------------------------- ### Listen to Multiple Property Changes Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/change-listeners.md Use the bulk `Config.onChange()` form to watch several properties with a single listener. The listener receives a `ModificationEvent` detailing which keys were modified. ```java import io.avaje.config.Config; import io.avaje.config.ModificationEvent; Config.onChange(event -> { Set changed = event.modifiedKeys(); System.out.println("Config changed. Modified keys: " + changed); if (changed.contains("database.host")) { reconnectDatabase(Config.get("database.host")); } if (changed.contains("cache.ttl")) { cacheService.setTtl(Config.getInt("cache.ttl", 300)); } }, "database.host", "cache.ttl"); ``` -------------------------------- ### Configure Root Logger Level Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/spring-boot.md Set the default logging level for the root logger in the main application properties file. ```properties root.level=INFO ``` -------------------------------- ### Listen for Boolean Property Changes Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Sets up a listener to be notified when a boolean configuration property's value changes. ```java // Listen for boolean changes Config.onChangeBool("feature.flag", isEnabled -> { featureManager.setEnabled(isEnabled); }); ``` -------------------------------- ### Set Environment Variables with Docker Run Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/environment-variables.md Pass environment variables to a Docker container at runtime using the '-e' flag with the 'docker run' command. ```bash docker run -e SERVER_PORT=9000 -e DATABASE_HOST=prod-db.example.com myapp:latest ``` -------------------------------- ### Defining a Configuration Class Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/troubleshooting.md Define a configuration class annotated with `@Config` to group related properties. The class must be on the classpath and within a scanned package. ```java package com.example.config; import io.avaje.config.Config; @Config public class DatabaseConfig { public final String host; public final int port; public DatabaseConfig(String host, int port) { this.host = host; this.port = port; } } ``` -------------------------------- ### Property Change Listeners Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md These methods allow you to register callbacks that will be executed when a specific configuration property changes its value at runtime. ```APIDOC ## Property Change Listeners ### Description Listen for runtime changes to specific configuration properties and execute callback functions. ### Methods - `Config.onChange(key, callback)`: Listen for string property changes. - `Config.onChangeInt(key, callback)`: Listen for integer property changes. - `Config.onChangeLong(key, callback)`: Listen for long property changes. - `Config.onChangeBool(key, callback)`: Listen for boolean property changes. ### Examples ```java // Listen for changes to a string property Config.onChange("app.mode", newMode -> { System.out.println("App mode changed to: " + newMode); }); // Listen for changes to an integer property Config.onChangeInt("server.port", newPort -> { System.out.println("Server port changed to: " + newPort); // Potentially restart server or update bindings }); ``` ``` -------------------------------- ### Listen for Integer Property Changes - Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Register a callback to be notified when a specific integer property's value changes at runtime. The callback receives the new integer value. ```java Config.onChangeInt("server.port", newVal -> {...}) ``` -------------------------------- ### Listen for String Property Changes - Avaje Config Source: https://github.com/avaje/avaje-config/blob/main/docs/LIBRARY.md Register a callback to be notified when a specific string property's value changes at runtime. The callback receives the new value. ```java Config.onChange("feature.flag", newVal -> {...}) ``` -------------------------------- ### Use Type-Safe Configuration Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/getting-started.md Inject and use the type-safe configuration class within your application services to access configuration values. ```java public class MyService { private final AppConfig config; public MyService(AppConfig config) { this.config = config; } } ``` -------------------------------- ### Add Avaje Dynamic Logback Dependency Source: https://github.com/avaje/avaje-config/blob/main/avaje-dynamic-logback/README.md Include this dependency in your project's pom.xml to enable the dynamic logging level functionality provided by Avaje Dynamic Logback. ```xml io.avaje avaje-dynamic-logback ... ``` -------------------------------- ### Add avaje-config Dependencies Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/spring-boot.md Include the avaje-config and avaje-aws-appconfig dependencies in your project. Note that avaje-config must be added explicitly as it's provided by avaje-aws-appconfig. ```xml io.avaje avaje-config 5.1 io.avaje avaje-aws-appconfig 1.6 ``` -------------------------------- ### AWS AppConfig Configuration Using Environment Variables Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/aws-appconfig-setup.md Reference environment variables for AWS AppConfig settings in application.yaml to dynamically set parameters like environment and polling interval. ```yaml aws.appconfig: enabled: true application: my-application environment: ${ENVIRONMENT:dev} configuration: ${CONFIG_PROFILE:default} pollingSeconds: ${POLLING_INTERVAL:45} ``` -------------------------------- ### Configure Test Logger Level Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/spring-boot.md Define logging levels specifically for tests, including overriding levels for specific packages like io.avaje. ```properties root.level=WARN io.avaje.level=DEBUG ``` -------------------------------- ### Enable AWS AppConfig in application.yaml Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/cloud-integration.md Configure avaje-config to load settings from AWS AppConfig by setting enabled to true and specifying application, environment, and configuration details. Environment variables can be used for dynamic values. ```yaml aws.appconfig: enabled: true application: ${ENVIRONMENT_NAME:dev}-my-application environment: ${ENVIRONMENT_NAME:dev} configuration: default ``` -------------------------------- ### Set Environment Variables on Linux/Mac Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/environment-variables.md Set environment variables using the 'export' command before running the Java application. This is a common method for Linux and macOS environments. ```bash export SERVER_PORT=9000 export DATABASE_HOST=prod-db.example.com java myapp.jar ``` -------------------------------- ### Accessing Configuration Properties Source: https://github.com/avaje/avaje-config/blob/main/docs/guides/troubleshooting.md Access nested configuration properties using dot notation. A default value can be provided if the property is not found. ```java // Access nested properties with dot notation int port = Config.getInt("server.port", 8080); // Provide default ```