当前位置: 首页 > news >正文

广州制作网站平台定州市建设局网站

广州制作网站平台,定州市建设局网站,wordpress调用文章第一张图片,精美wordpress模板下载前言 在项目启动时#xff0c;需要读取一些业务上大量的配置文件#xff0c;用来初始化数据或者配置设定值等#xff0c;我们都知道使用SpringBoot的ConfigurationProperties注解 application.yml配置可以很方便的读取这些配置#xff0c;并且映射成对象很方便的使用需要读取一些业务上大量的配置文件用来初始化数据或者配置设定值等我们都知道使用SpringBoot的ConfigurationProperties注解 application.yml配置可以很方便的读取这些配置并且映射成对象很方便的使用但是这些配置文件比较多的时候而且不希望与application.yml放在一起那么用SpringBoot如何实现呢。 my-config.yml my-config:key1: hello方法1 导入配置文件 application.yml中可以导入这些配置文件然后继续使用ConfigurationProperties注解这样做的好处是最简单的而且还可以增加my-conf-profile.yml的文件以达到根据profile切换配置文件的目的 application.yml spring:config:import: my-config.ymlMyConfig.java Data Configuration ConfigurationProperties(prefixmy-config) public class MyConfig {private String key1; }方法2 使用PropertySource注解加载配置文件 MyConfig.java Data Configuration ConfigurationProperties(prefixmy-config) PropertySource(value classpath:my-config.yml, factory YamlPropertySourceFactory.class) public class MyConfig {private String key1; }由于PropertySource注解默认只支持properties格式的配置文件所以要自定义yaml文件读取方式 YamlPropertySourceFactory.java import org.springframework.boot.env.YamlPropertySourceLoader; import org.springframework.core.env.PropertySource; import org.springframework.core.io.support.EncodedResource; import org.springframework.core.io.support.PropertySourceFactory;public class YamlPropertySourceFactory implements PropertySourceFactory {Overridepublic PropertySource? createPropertySource(String name, EncodedResource resource) throws IOException {return new YamlPropertySourceLoader().load(resource.getResource().getFilename(), resource.getResource()).get(0);} }方法3 使用YamlPropertySourceLoader Binder进行手动绑定 以上方法都会将MyConfig对象注入到Spring容器中去而且配置文件也会在上下文的环境中存在如果不想放入容器或者想对绑定的过程做更定制化的处理比如判断文件修改时间等那么需要手动绑定生成配置对象。 MyConfig.java Data public class MyConfig {private String key1; }BindDemo.java import org.springframework.boot.context.properties.bind.BindResult; import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.context.properties.source.ConfigurationPropertySource; import org.springframework.boot.env.YamlPropertySourceLoader; import org.springframework.core.env.PropertySource; import org.springframework.core.io.ClassPathResource;public class BindDemo {public MyConfig getMyConfig() throws IOException {Resource resource new ClassPathResource(my-config.yml);// 查看文件最后修改时间FileTime lastModifiedTime Files.getLastModifiedTime(resource.getFile().toPath());String format lastModifiedTime.toInstant().atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm:ss));System.out.println(system-dic.yml last modified time: format);ListPropertySource? load new YamlPropertySourceLoader().load(resource.getFilename(), resource);Binder binder new Binder(ConfigurationPropertySource.from(load.get(0)));BindResultDicProperties bind binder.bind(my-config, DicProperties.class);return bind.get();} }
http://www.pierceye.com/news/561598/

相关文章:

  • 西乡塘网站建设企业vi形象设计是什么意思
  • 做服装到哪个网站拿货品质好广告软文小故事200字
  • 廊坊网站建设设计wordpress上传后如何访问
  • 禅城网站制作网站推广优化技巧大全
  • xampp做的网站能搜索吗广州外贸公司集中地
  • 茶网站建设网站的基础建设
  • 大型机械网站建设公司免费的cms视频网站
  • 杭州做网站哪家好在线设计平台都有哪些比较好用的
  • 内外网网站栏目建设方案专门做电容的网站
  • 一般网站字体多大有没有做公司网站的
  • 做国外进口衣服的网站好怎么推广公众号
  • 安县建设局网站网站建设分金手指排名一
  • 社区网站制作教程社交媒体营销
  • 云南省建设工程质量监督管理站网站房产网站推广
  • 做网站挣钱吗营销导向的企业网站建设步骤
  • 优化网站 优帮云网站是意识形态建设
  • 网站内容建设运维服务wordpress envato主题
  • 响应式网站的几种尺寸推广网站的几种方法
  • php 打开网站东莞网站建设网页推广
  • 正品海外购网站有哪些公司网站开发费用兴田德润在哪儿
  • 怎样做编辑发到网站自由建网站的网络程序
  • 网站开发 卡片cms建站系统 下载
  • 新浪门户网站是谁做的科技网站建设
  • 免费网站建设合同书山西网站建设企业
  • 网站建设空间什么意思学做网站什么语言合适
  • 网站开发的形式有( )友情链接英文
  • 帝国网站管理系统前台免费photoshop下载
  • 深圳一百讯网站建设wordpress汉化包
  • 建设一个班级网站的具体步骤自己的网站源代码一片空白
  • 初创公司 建网站wordpress 模板获取数据库