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

邯郸网站建设怎么开发响应式手机模板WordPress

邯郸网站建设怎么开发,响应式手机模板WordPress,做海报好的psd网站,郑州防疫新闻SpringCloud为我们提供了bootstrap.properties的属性文件#xff0c;我们可以在该属性文件里做我们的服务配置。可是#xff0c;我们知道SpringBoot已经为我们提供了做服务配置的属性文件application.properties#xff0c;那么这两个配置文件有什么区别呢#xff1f;在Spr…       SpringCloud为我们提供了bootstrap.properties的属性文件我们可以在该属性文件里做我们的服务配置。可是我们知道SpringBoot已经为我们提供了做服务配置的属性文件application.properties那么这两个配置文件有什么区别呢在SpringCloud里是否能用bootstrap代替application做服务的配置要解决这个问题我们必须先讨论一下SpringCloud的引导。  一、  官方文档描述 引导应用程序上下文   一个Spring Cloud应用程序通过创建一个“引导”上下文来进行操作这个上下文是主应用程序的父上下文。开箱即用负责从外部源加载配置属性还解密本地外部配置文件中的属性。这两个上下文共享一个Environment这是任何Spring应用程序的外部属性的来源。Bootstrap属性的优先级高因此默认情况下不能被本地配置覆盖。 引导上下文使用与主应用程序上下文不同的外部配置约定因此使用bootstrap.yml application.yml或.properties代替引导和主上下文的外部配置。例bootstrap.yml spring:application:name: foocloud:config:uri: ${SPRING_CONFIG_URI:http://localhost:8888} 如果您的应用程序需要服务器上的特定于应用程序的配置那么设置spring.application.name在bootstrap.yml或application.yml中是个好主意。 您可以通过设置spring.cloud.bootstrap.enabledfalse例如在系统属性中来完全禁用引导过程。   二、引导上下文  1. 关于引导上下文位置          这里我们可以发现几个关键的类,其中BootstrapApplicationListener是核心中的核心可自行查看源码      这个类是一个监听器它用于监听ApplicationEnvironmentPreparedEvent事件而EventPublishingRunListener在SpringBoot启动时会触发该事件。如果不理解的这个类的朋友请务必先了解SpringBoot启动过程     2.这个上下文是主应用程序的父上下文       这个工作主要分为两个层面1.创建上下文引导 2.设置为其为当前程序的父级上下文          1) 我们先看看onApplicationEvent方法该方法首先读取spring.cloud.bootstrap.enabled的属性值如果为false那么就直接return。这也就是官方文档里的说明可以用此属性禁用引导的理由。    2)紧接着它会从当前应用程序SpringApplication试着在所有的ApplicationInitializer中获取ParentContextApplicationContextInitializer如果找到的话就把该类下的parent做为引导上下文。    3)如果没有找到ParentContextApplicationContextInitializer则通过 bootstrapServiceContext方法来创建引导上下文其中如下代码请大家留意下 ListString names SpringFactoriesLoader.loadFactoryNames(BootstrapConfiguration.class, classLoader);          看到SpringFactoriesLoader不用想一定会在META-INF/spring.factoies里找配置的BootstrapConfiguration的进行实例化                4通过如下代码创建引导上下文对象 SpringApplicationBuilder builder new SpringApplicationBuilder().profiles(environment.getActiveProfiles()).bannerMode(Mode.OFF).environment(bootstrapEnvironment).properties(spring.application.name: configName).registerShutdownHook(false).logStartupInfo(false).web(false);if (environment.getPropertySources().contains(refreshArgs)) {// If we are doing a context refresh, really we only want to refresh the// Environment, and there are some toxic listeners (like the// LoggingApplicationListener) that affect global static state, so we need a// way to switch those off.builder.application().setListeners(filterListeners(builder.application().getListeners()));}ListClass? sources new ArrayList();for (String name : names) {Class? cls ClassUtils.resolveClassName(name, null);try {cls.getDeclaredAnnotations();}catch (Exception e) {continue;}sources.add(cls);}AnnotationAwareOrderComparator.sort(sources);builder.sources(sources.toArray(new Class[sources.size()]));final ConfigurableApplicationContext context builder.run();    5最后通过如下方法设置引导上下文为当前应用程序的上下文 // Make the bootstrap context a parent of the app contextaddAncestorInitializer(application, context);      3. 负责从外部源加载配置属性还解密本地外部配置文件中的属性        开箱即用理解起来很简单。通过2.2分析引导程序在SpringBoot的启动前就帮我们创建好了当然也就开箱即用了。  下面我们看一下spring-cloud-context.jar下的META-INF/spring.factoies文件:      # AutoConfiguration org.springframework.boot.autoconfigure.EnableAutoConfiguration\ org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration,\ org.springframework.cloud.autoconfigure.RefreshAutoConfiguration,\ org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration,\ org.springframework.cloud.autoconfigure.LifecycleMvcEndpointAutoConfiguration# Application Listeners org.springframework.context.ApplicationListener\ org.springframework.cloud.bootstrap.BootstrapApplicationListener,\ org.springframework.cloud.bootstrap.LoggingSystemShutdownListener,\ org.springframework.cloud.context.restart.RestartListener# Bootstrap components org.springframework.cloud.bootstrap.BootstrapConfiguration\ org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration,\ org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration,\ org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration,\ org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration View Code  我们来看一下  BootstrapConfiguration下面配置的引导程序类     org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration这个类主要解析加载外部化配置属性     org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration主要配置文件中前缀为{cipher}的相关解密熟悉spring-boot-starter-security在springcloud应用的朋友一定不陌生     org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration主要是监听EnvironmentChangeEvent事件用于刷新ConfigurationProperties标记的配置     org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration主要解析配置文件中的${}占位符    4. 这两个上下文共享一个Environment        既然引导上下文为当前主程序的父级上下文那么就可以确定他们共享Environment至于为什么请阅读文章第一部分  5. BootStrap属性的优先级高因此默认情况下不能被本地配置覆盖       对于引导程序bootstrap.yml比application.yml优先级更高更不可能被application.yml文件里的所覆盖  三、总结   1引导程序上下文在prepareEnvironment的阶段就会被创建创建时会读取bootstrap.properties|yml 在内容作为引导配置, 因此bootstrap优先于application加载。引导程序非常类似于bios而bootstrap.application就相当于设置bios的相关参数   2boostrap的属性文件在以下情景下会使用     配置中心config-server里请用bootstrap属性文件       解密属性文件时最好使用bootstrap属性文件     需要自定义引导程序时使用bootstrap属性文件主要一定不要被我们主程序扫描到   3application会覆盖bootstrap中的非引导配置因此不建议两种类型配置文件同时存在。简单粗暴的做法是在springcloud应用中用bootstrap属性文件代替application一统江湖嘛毕竟Envrionment是共享的。   4)  在阅读官方文档时一定要结合源代码深入分析才能更好的理解其用意 转载于:https://www.cnblogs.com/whx7762/p/11232019.html
http://www.yutouwan.com/news/131462/

相关文章:

  • 专业俄文网站建设网站建设创建
  • 临汾工程建设招标投标网站发稿计划
  • 北京金港建设股份有限公司网站自己做手机网站
  • 网站编程课程设计心得体会怎么介绍做网站技术
  • 网站后台管理系统管理员登录深圳公司网站设计
  • 番禺网站建设知乎合肥百度推广排名优化
  • 网站设计经典案例欣赏免费注册入口
  • 知乎 拒绝 朋友 做网站论坛网站开发平台
  • 高境网站建设网站编辑专题怎么做
  • 亿客搜网站建设广告网站建设最专业
  • 扬州网站建设文章seo网站优化策划案
  • php 网站源代码修改wordpress登陆用户名和密码
  • 江苏省建设厅副厅长网站网站水印图片欣赏
  • 辽宁旅游网站开发wordpress 机械模板下载
  • 网上购物最便宜的网站网站架设
  • 安康网站建设小程序建阅读网站
  • 哪些做任务可以赚钱的网站南宁网站建设官网
  • 网站打开显示站点目录网站建设费入如保入账
  • 山东网站建设优化技术怎么简单页网站
  • 网站主目录wordpress文章写html
  • 做代码的网站新闻类软文营销案例
  • 营销型网站 易网拓上海网站专业制作
  • 郑州视频网站建设大概多少钱网站 编码文档
  • 成都的建站公司免费商城建站平台
  • 网站建设选用平台分析免费开源的建站系统
  • 做公众号封面的网站成都html5网站设计
  • 许昌做网站汉狮网络论坛推广工具
  • 学校门户网站建设工作汇报施工合同在哪个建设网站下载
  • 铜陵市网站建设江阴哪家做网站便宜
  • No商业网站建设织梦网站导航固定