RPC框架项目----读取yml配置文件

实现工具:

hutool工具包里的YamlUtil和BeanUtil


实现代码:

有前缀

Object o = YamlUtil.loadByPath(fileName.toString()).get("rpc");
return BeanUtil.toBean(o, configClass);


无前缀

Object o = YamlUtil.loadByPath(fileName.toString());
return BeanUtil.toBean(o, configClass);


fileName:配置文件名

configClass:配置实体类


思考:

YamlUtil.loadByPath得到的是hutool里自定义的一个类Dict,该类继承了LinkedHashMap

通过BeanUtil.toBean可以转成想要的类

0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
鱼友4886
下载 APP