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 | 内置配置源:
PropertiesConfigSource- Properties file source (priority: 50) - Properties文件源YamlConfigSource- YAML file source (priority: 50) - YAML文件源EnvironmentConfigSource- Environment variables (priority: 100) - 环境变量源SystemPropertiesConfigSource- System properties (priority: 50) - 系统属性源CommandLineConfigSource- Command line arguments (priority: 200) - 命令行参数源InMemoryConfigSource- In-memory configuration (priority: 10) - 内存配置源CompositeConfigSource- Composite source with priority merging - 组合源(优先级合并)
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:
-
ClassDescriptionCommand Line Arguments Configuration Source 命令行参数配置源Composite Configuration Source 组合配置源Configuration Source Interface 配置源接口Environment Variables Configuration Source 环境变量配置源In-Memory Configuration Source 内存配置源Properties File Configuration Source Properties文件配置源System Properties Configuration Source 系统属性配置源YAML Configuration Source YAML配置源