owner:配置文件管理解决方案笔记

来源:互联网 发布:python三本经典书籍 编辑:程序博客网 时间:2024/05/17 04:20

properties文件:

server.http.port=80server.host.name=foobar.comserver.max.threads=100

对应的 java 文件:

//@HotReload(value=10, unit = TimeUnit.SECONDS)@Sources({ "classpath:ServerConfig.properties" })public interface ServerConfig extends Reloadable  {@Key("server.http.port")int port();@Key("server.host.name")String hostname();@Key("server.max.threads")@DefaultValue("42")int maxThreads();}

@Sources里面可以配置多个文件,其他看字面意思因该就能理解吧

测试:

public static void main(String[] args) {    ServerConfig cfg = ConfigFactory.create(ServerConfig.class);    System.out.println(cfg.hostname());        ServerConfig instance = ConfigCache.getOrCreate(ServerConfig.class);        System.out.println(instance.hostname());    }


建议使用configCache获取,单例嘛。


源地址:http://owner.aeonbits.org/docs/features/


                                             
0 0
原创粉丝点击