Class ConfigBinder

java.lang.Object
cloud.opencode.base.config.bind.ConfigBinder

public class ConfigBinder extends Object
Configuration Binder 配置绑定器

Binds configuration properties to POJOs using reflection with support for nested configurations and type conversion.

使用反射将配置属性绑定到POJO,支持嵌套配置和类型转换。

Features | 主要功能:

  • POJO binding with reflection - 使用反射的POJO绑定
  • Nested configuration support - 嵌套配置支持
  • Automatic type conversion - 自动类型转换
  • Field name to key conversion - 字段名到键的转换

Usage Examples | 使用示例:

@ConfigProperties(prefix = "database")
public class DatabaseConfig {
    private String url;
    private String username;
    private int maxPoolSize;

    @NestedConfig
    private PoolConfig pool;

    // getters and setters
}

ConfigBinder binder = new ConfigBinder(config, converters);
DatabaseConfig dbConfig = binder.bind("database", DatabaseConfig.class);

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
Since:
JDK 25, opencode-base-config V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

  • Method Details

    • bind

      public <T> T bind(String prefix, Class<T> type)
      Bind configuration to new instance 绑定配置到新实例
      Type Parameters:
      T - target type | 目标类型
      Parameters:
      prefix - configuration prefix | 配置前缀
      type - target class | 目标类
      Returns:
      bound instance | 绑定的实例
    • bindTo

      public <T> void bindTo(String prefix, T target)
      Bind configuration to existing instance 绑定配置到现有实例
      Type Parameters:
      T - target type | 目标类型
      Parameters:
      prefix - configuration prefix | 配置前缀
      target - target instance | 目标实例