Java Application Configuration: Libraries and Tools for Settings Management

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Java Application Configuration: A Complete Overview of Libraries and Tools



Configuration is one of the key aspects of modern Java application development. Well-organized settings management allows you to separate code and data, simplify deployment across different environments (dev, test, prod), and ensure system flexibility. In this article, we will review the main libraries and approaches that will help you effectively manage Java application configuration.



Why Do You Need a Separate Library for Configuration?

Using the standard java.util.Properties or reading environment variables via System.getenv() is a basic approach, but it has limitations:

  • Lack of support for complex structures (nested objects, lists)
  • Difficulty with validation and typing
  • Challenges with overriding settings for different profiles
  • No automatic configuration reloading

Specialized libraries solve these problems by providing a convenient API, support for various formats (YAML, JSON, HOCON), and integration with frameworks.



1. Spring Boot Configuration (Spring Framework)

The most popular approach in the Spring ecosystem. It allows you to manage settings via application.properties or application.yml.



Example application.yml:

server:  port: 8080  context-path: /api

database: url: jdbc:postgresql://localhost:5432/mydb username: ${DB_USER:admin} password: ${DB_PASSWORD:secret} pool-size: 10


Example Java class for configuration binding:

import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.stereotype.Component;

@Component@ConfigurationProperties(prefix = "database")public class DatabaseConfig { private String url; private String username; private String password; private int poolSize;

// getters and setters public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } // ... remaining methods}


Advantages:

  • Deep integration with Spring Boot
  • Automatic validation via @Validated
  • Profile support (application-dev.yml, application-prod.yml)
  • Ability to use SpEL for dynamic values


2. Typesafe Config (Lightbend Config)

A library developed for Scala and Java, using the HOCON format (Human-Optimized Config Object Notation). It features strict typing and support for configuration inheritance.



Example application.conf file:

app {  name = "MyApp"  version = ${?APP_VERSION} // substitution from environment variable  http {    host = "0.0.0.0"    port = 8080  }  features {    enabled = [cache, logging]    cache {      ttl = 300    }  }}


Example loading in Java:

import com.typesafe.config.Config;import com.typesafe.config.ConfigFactory;

public class AppConfig { private static final Config config = ConfigFactory.load();

public static String getAppName() { return config.getString("app.name"); }

public static int getCacheTtl() { return config.getInt("app.features.cache.ttl"); }}


Advantages:

  • Support for substitutions (${...}) and environment variables
  • Configuration inheritance (include)
  • Strict typing: separate methods for String, Int, Duration, MemorySize
  • Ability to merge multiple files


3. Apache Commons Configuration

A classic library from Apac

Recommendations