Java Application Configuration: Overview of Libraries and Tools

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: Overview of Libraries and Tools



Configuration management is one of the key tasks in developing modern Java applications. The flexibility and ease of configuration determine how easily an application can adapt to different environments: development, testing, production. In this article, we will look at the main approaches and popular libraries for working with configuration in Java.



Why are configuration tools needed?

The standard java.util.Properties and reading from .properties files work, but have limitations: lack of support for hierarchical structures, complexity of merging configurations from different sources, weak typing. Modern libraries solve these problems and provide:

  • Support for multiple formats: YAML, JSON, HOCON, XML;
  • Hierarchical parameter overriding (system properties → environment variables → files);
  • Typed access to values;
  • Support for profiles and dynamic updates.


1. Spring Boot — Industry Standard

Spring Boot is the most popular framework for creating microservices and web applications. Its configuration system is flexible and powerful.

Key features:

  • Support for application.properties and application.yml;
  • Profiles (application-dev.yml, application-prod.yml);
  • @ConfigurationProperties annotation for typed bean objects;
  • Source hierarchy: command line → JNDI → system properties → environment variables → files.

Usage example:

// application.ymlserver:  port: 8080app:  name: MyApp  timeout: 30

// Java class for configuration@ConfigurationProperties(prefix = "app")public class AppConfig { private String name; private int timeout; // getters and setters}

// Usage@RestControllerpublic class DemoController { @Autowired private AppConfig config;

@GetMapping("/info") public String info() { return config.getName() + " timeout: " + config.getTimeout(); }}

Spring Boot automatically binds YAML properties to Java object fields, providing strong typing and validation.



2. MicroProfile Config — Standard for Microservices

MicroProfile Config is part of the Eclipse MicroProfile specification, designed for cloud and microservice architectures. It provides a unified API for accessing configuration.

Key features:

  • Support for multiple sources: files, environment variables, JNDI, custom;
  • @Inject and @ConfigProperty annotations;
  • Dynamic value updates (when using the appropriate extension);
  • Standard type converters.

Example:

@ApplicationScopedpublic class ConfigService {    @Inject    @ConfigProperty(name = "app.max.connections", defaultValue = "10")    private int maxConnections;

@Inject @ConfigProperty(name = "db.url") private Optional<String> dbUrl;

public void printConfig() { System.out.println("Max connections: " + maxConnections); dbUrl.ifPresent(url -> System.out.println("DB URL: " + url)); }}

The library allows you to easily override parameters through environment variables without changing code, which is critical for container environments (Docker, Kubernetes).



3. Typesafe Config (Lightbend Config)

Originally created for Scala, but works great in Java as well. It uses the HOCON format (Human-Optimized Config Object Notation) — a superset of JSON.

Adv

Recommendations