Package cloud.opencode.base.config


package cloud.opencode.base.config
Configuration Management Core Package 配置管理核心包

This package provides unified configuration management capabilities including multi-source configuration loading, type-safe access, hot reload, and configuration binding.

此包提供统一的配置管理能力,包括多配置源加载、类型安全访问、热更新和配置绑定。

Features | 主要功能:

  • Multi-source configuration: Properties, YAML, Environment, System Properties, Command Line - 多配置源: Properties、YAML、环境变量、系统属性、命令行
  • Priority-based source merging - 基于优先级的配置源合并
  • Type-safe configuration retrieval with 30+ built-in converters - 内置30+转换器的类型安全配置读取
  • Placeholder resolution (${key} syntax) - 占位符解析 (${key} 语法)
  • Hot reload with file change monitoring - 文件变更监听的热更新
  • Configuration validation - 配置验证
  • Record and POJO binding - Record和POJO绑定

Architecture | 架构概览:

┌─────────────────────────────────────────────────────────────────┐
│                         Application Layer                        │
└─────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────┐
│                      OpenConfig Facade                           │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────────┐  │
│  │  get/bind   │  │  Listeners  │  │   Placeholder ${key}    │  │
│  └─────────────┘  └─────────────┘  └─────────────────────────┘  │
└─────────────────────────────────────────────────────────────────┘
                                │
        ┌───────────────────────┼───────────────────────┐
        ▼                       ▼                       ▼
┌─────────────────┐   ┌─────────────────┐   ┌─────────────────┐
│  Converters     │   │  ConfigBinder   │   │  Validators     │
└─────────────────┘   └─────────────────┘   └─────────────────┘

Quick Start | 快速开始:

// Use default configuration
String dbUrl = OpenConfig.getString("database.url");
int port = OpenConfig.getInt("server.port", 8080);

// Build custom configuration
Config config = OpenConfig.builder()
    .addClasspathResource("application.properties")
    .addEnvironmentVariables()
    .addSystemProperties()
    .enableHotReload()
    .build();

Package Structure | 包结构:

Thread Safety | 线程安全:

  • All public APIs are thread-safe - 所有公开API都是线程安全的
  • Configuration snapshots are immutable - 配置快照不可变
  • Hot reload uses atomic reference switching - 热更新使用原子引用切换
Since:
JDK 25, opencode-base-config V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also: