Class PropertiesConfigSource
java.lang.Object
cloud.opencode.base.config.source.PropertiesConfigSource
- All Implemented Interfaces:
ConfigSource
Properties File Configuration Source
Properties文件配置源
Loads configuration from .properties files, supporting both classpath and filesystem resources.
从.properties文件加载配置,支持类路径和文件系统资源。
Features | 主要功能:
- Classpath and filesystem support - 支持类路径和文件系统
- Hot reload for file-based sources - 文件源支持热重载
- UTF-8 encoding support - UTF-8编码支持
- Last modified time tracking - 最后修改时间跟踪
Usage Examples | 使用示例:
// From classpath
ConfigSource source = new PropertiesConfigSource("application.properties", true);
// From filesystem
ConfigSource source = new PropertiesConfigSource(Path.of("/etc/app/config.properties"));
// Hot reload
if (source.supportsReload()) {
source.reload();
}
Performance | 性能特性:
- Time complexity: O(n) for loading - 时间复杂度: 加载为O(n)
- Properties cached in memory - 属性缓存在内存中
- Reload checks modification time - 重载检查修改时间
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Immutable properties map - 不可变属性映射
- Since:
- JDK 25, opencode-base-config V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionPropertiesConfigSource(String resource, boolean classpath) Create properties source from classpath or filesystem 从类路径或文件系统创建属性源PropertiesConfigSource(Path file) Create properties source from filesystem path 从文件系统路径创建属性源 -
Method Summary
Modifier and TypeMethodDescriptiongetName()Get configuration source name 获取配置源名称intGet configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)Get all configuration properties 获取所有配置属性voidreload()Reload configuration from source 从源重新加载配置booleanCheck if source supports hot reload 检查源是否支持热重载Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ConfigSource
getProperty
-
Constructor Details
-
PropertiesConfigSource
Create properties source from classpath or filesystem 从类路径或文件系统创建属性源- Parameters:
resource- resource path | 资源路径classpath- true for classpath, false for filesystem | 类路径为true,文件系统为false
-
PropertiesConfigSource
Create properties source from filesystem path 从文件系统路径创建属性源- Parameters:
file- file path | 文件路径
-
-
Method Details
-
getName
Description copied from interface:ConfigSourceGet configuration source name 获取配置源名称- Specified by:
getNamein interfaceConfigSource- Returns:
- source name | 源名称
-
getProperties
Description copied from interface:ConfigSourceGet all configuration properties 获取所有配置属性Performance | 性能:
This method should return a cached immutable map for best performance.
此方法应返回缓存的不可变映射以获得最佳性能。
- Specified by:
getPropertiesin interfaceConfigSource- Returns:
- configuration properties map | 配置属性映射
-
getPriority
public int getPriority()Description copied from interface:ConfigSourceGet configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)Default Priorities | 默认优先级:
- CommandLine: 200
- Environment: 100
- Properties/YAML: 50
- InMemory: 10
- Specified by:
getPriorityin interfaceConfigSource- Returns:
- priority value | 优先级值
-
supportsReload
public boolean supportsReload()Description copied from interface:ConfigSourceCheck if source supports hot reload 检查源是否支持热重载- Specified by:
supportsReloadin interfaceConfigSource- Returns:
- true if hot reload supported | 如果支持热重载返回true
-
reload
public void reload()Description copied from interface:ConfigSourceReload configuration from source 从源重新加载配置This method is called when hot reload is enabled.
启用热重载时会调用此方法。
- Specified by:
reloadin interfaceConfigSource
-