Package cloud.opencode.base.config.source


package cloud.opencode.base.config.source
Configuration Sources Package 配置源包

This package provides various configuration source implementations for loading configuration from different locations and formats.

此包提供各种配置源实现,用于从不同位置和格式加载配置。

Features | 主要功能:

  • Multiple source types - 多种配置源类型
  • Priority-based merging - 基于优先级的合并
  • Hot reload support - 热更新支持
  • SPI extensibility - SPI扩展性

Built-in Sources | 内置配置源:

Priority Order (High to Low) | 优先级顺序(高到低):

Command Line (200) → Environment (100) → System Properties (50) →
Properties/YAML (50) → InMemory (10)

Usage Examples | 使用示例:

// Properties source from classpath
ConfigSource props = new PropertiesConfigSource("application.properties", true);

// Properties source from file system
ConfigSource fileProps = new PropertiesConfigSource(Path.of("/etc/app/config.properties"));

// Environment variables with prefix filtering
ConfigSource env = new EnvironmentConfigSource("APP_");

// Command line arguments
ConfigSource cmdLine = new CommandLineConfigSource(args);

// Composite source
ConfigSource composite = new CompositeConfigSource(List.of(props, env, cmdLine));

Implementing Custom Sources | 实现自定义配置源:

public class RedisConfigSource implements ConfigSource {
    @Override
    public String getName() { return "redis"; }

    @Override
    public Map<String, String> getProperties() {
        // Load from Redis
    }

    @Override
    public int getPriority() { return 80; }

    @Override
    public boolean supportsReload() { return true; }
}
Since:
JDK 25, opencode-base-config V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also: