• JadConfig 注解驱动的java 配置管理包


    JadConfig 是graylog 开源的一个基于注解驱动的java 配置管理包,graylog server 对于配置的管理就是使用了此包
    JadConfig 使用比较简单,但是功能还是很强大的,配置包含了校验处理

    参考使用

    • 使用默认PropertiesRepository 处理
     
    ConfigurationBean bean = new ConfigurationBean();
    new JadConfig(new PropertiesRepository("my.properties"), bean).process();

    Repository 是一个接口,定义的配置如何加载(一般是加载为properties)

    • guice 集成
    Injector injector = Guice.createInjector(new NamedConfigParametersModule(Collections.singleton(configurationBean)));
     
    public class MyConfigBean {
        @Parameter("my.custom.config")
        public String customConfig;
    }
     
    // Create injector and register NamedConfigParametersModule.
    // [...]
     
    public class MyClass {
        @Inject
        public MyClass(@Named("my.custom.config") String customConfig) {
            // ...
        }
    }
     
    // MyClass will be instantiated with the value of customConfig from the MyConfigBean instance.
    MyClass myClass = injector.getInstance(MyClass.class);

    注意以上方法需要先加载JadConfig,然后基于NamedConfigParametersModule 的模块包含配置bean

    说明

    JadConfig 是一个很不错的配置管理包,使用简单,扩展点不少,包含了如何加载配置,以及类型转换的,项目中还是值得使用的

    参考资料

    https://github.com/Graylog2/JadConfig
    https://github.com/Netflix/archaius

  • 相关阅读:
    Linux rm rf 命令
    Oracle时间戳转换日期
    PHP执行代码的步骤
    PHP字符串比较
    PHP调整图片大小
    PHP学习笔记2022年9月13日
    索引数组
    腾讯云安全组开放端口不生效的解决办法
    php中使用fsockopen实现异步请求
    创建ftp账户并赋予指定权限
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/16729418.html
Copyright © 2020-2023  润新知