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

网站建设的基本流程是什么江苏省现代化示范校建设网站

网站建设的基本流程是什么,江苏省现代化示范校建设网站,成都网站建设推广港哥,中小企业名录查询官网文章目录初始化DefaultBootstrapContext开启Headless模式获取监听器并启动封装命令行参数准备环境打印Banner创建上下文容器预初始化上下文容器刷新Spring容器打印启动时间发布事件执行特定的run方法上一篇《【SpringBoot3.0源码】启动流程源码解析 • 上》#xff0c;主要讲解… 文章目录初始化DefaultBootstrapContext开启Headless模式获取监听器并启动封装命令行参数准备环境打印Banner创建上下文容器预初始化上下文容器刷新Spring容器打印启动时间发布事件执行特定的run方法上一篇《【SpringBoot3.0源码】启动流程源码解析 • 上》主要讲解了new SpringApplication()设置了一些初始化器和监听器接下来我们讲解下run方法的调用。 步入run方法 public ConfigurableApplicationContext run(String... args) {// 记录时间long startTime System.nanoTime();// 利用BootstrapRegistryInitializer初始化DefaultBootstrapContext对象DefaultBootstrapContext bootstrapContext createBootstrapContext();ConfigurableApplicationContext context null;// 开启了Headless模式configureHeadlessProperty();// 获取监听器SpringApplicationRunListeners listeners getRunListeners(args);// 发布ApplicationStartingEvent事件listeners.starting(bootstrapContext, this.mainApplicationClass);try {// 根据命令行参数实例化一个ApplicationArgumentsApplicationArguments applicationArguments new DefaultApplicationArguments(args);// 准备环境ConfigurableEnvironment environment prepareEnvironment(listeners, bootstrapContext, applicationArguments);// 打印BannerBanner printedBanner printBanner(environment);// 据webApplicationType创建不同的Spring上下文容器有三种context createApplicationContext();context.setApplicationStartup(this.applicationStartup);// 预初始化spring上下文prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);// 刷新Spring容器refreshContext(context);afterRefresh(context, applicationArguments);// 打印启动时间Duration timeTakenToStartup Duration.ofNanos(System.nanoTime() - startTime);if (this.logStartupInfo) {new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), timeTakenToStartup);}// 发布ApplicationStartedEvent事件和AvailabilityChangeEvent事件listeners.started(context, timeTakenToStartup);// 获取Spring容器中的ApplicationRunner/CommandLineRunner类型的Bean,并执行run方法callRunners(context, applicationArguments);}catch (Throwable ex) {if (ex instanceof AbandonedRunException) {throw ex;}// 发布ApplicationFailedEvent事件handleRunFailure(context, ex, listeners);throw new IllegalStateException(ex);}try {if (context.isRunning()) {Duration timeTakenToReady Duration.ofNanos(System.nanoTime() - startTime);// 发布ApplicationReadyEvent事件和AvailabilityChangeEvent事件listeners.ready(context, timeTakenToReady);}}catch (Throwable ex) {if (ex instanceof AbandonedRunException) {throw ex;}// 发布ApplicationFailedEvent事件handleRunFailure(context, ex, null);throw new IllegalStateException(ex);}return context; }初始化DefaultBootstrapContext 步入createBootstrapContext方法 开启Headless模式 Headless模式是在缺少显示屏、键盘或者鼠标的系统配置。 步入configureHeadlessProperty方法 private void configureHeadlessProperty() {System.setProperty(SYSTEM_PROPERTY_JAVA_AWT_HEADLESS,System.getProperty(SYSTEM_PROPERTY_JAVA_AWT_HEADLESS, Boolean.toString(this.headless))); }启用headless模式需要使用setProperty方法去设置相应的系统属性。 System.setProperty(“java.awt.headless”,”true”)如果想在一个相同的程序 中使用headless和传统环境你可以使用下面的命令行来完成 java -Djava.awt.headlesstrue获取监听器并启动 SpringApplicationRunListeners listeners getRunListeners(args); listeners.starting(bootstrapContext, this.mainApplicationClass);获取SpringApplicationRunListenersSpringBoot提供了一个EventPublishingRunListener它实现了SpringApplicationRunListener接口 Spring会利用这个类发布一个ApplicationContextInitializedEvent事件可以通过定义ApplicationListener来监听这个事件。 步入getRunListeners方法调用getSpringFactoriesInstances方法获取监听器这个方法前面前面讲过因为在前面已经put进m缓存中所以这里可以根据参数获取value值。 最后返回一个SpringApplicationRunListener实例。 接下来回去调用 listeners.starting(bootstrapContext, this.mainApplicationClass);步入starting方法 步入doWithListeners方法 首先会调用listenerAction (listener) - listener.starting(bootstrapContext) 步入starting方法 步入multicastInitialEvent方法 步入refreshApplicationListeners方法 这7个监听器是我们之前加载到的 调用this.initialMulticaster::addApplicationListener方法 显式删除代理的目标如果已注册以避免对同一侦听器进行双重调用。 add到applicationListeners的set集合中。 执行完返回 步入multicastEvent方法 步入invokeListener方法 doInvokeListener listener.onApplicationEvent(event); onApplicationStartingEvent beforeInitialize 最后回到这里 封装命令行参数 命令行参数配置 DefaultApplicationArguments构造方法 public DefaultApplicationArguments(String... args) {Assert.notNull(args, Args must not be null);this.source new Source(args);this.args args; }准备环境 读取环境变量操作系统的环境变量/JVM的环境变量读取配置文件信息基于监听器会利用EventPublishingRunListener发布一个ApplicationEnvironmentPreparedEvent事件默认会有一个EnvironmentPostProcessorApplicationListener来处理这个事件当然也可以通过自定义ApplicationListener来处理这个事件当ApplicationListener接收到这个事件之后就会解析application.properties、application.yml文件并添加到Environment中。 步入prepareEnvironment方法 private ConfigurableEnvironment prepareEnvironment(SpringApplicationRunListeners listeners,DefaultBootstrapContext bootstrapContext, ApplicationArguments applicationArguments) {// 根据不同的web类型创建不同实现的Environment对象读取java环境变量和系统环境变量ConfigurableEnvironment environment getOrCreateEnvironment();// 将命令行参数读取环境变量中configureEnvironment(environment, applicationArguments.getSourceArgs());// 将PropertieSource的配置信息 放在第一位它的优先级是最低的ConfigurationPropertySources.attach(environment);// 发布了ApplicationEnvironmentPreparedEvent 的监听器 读取了全局配置文件listeners.environmentPrepared(bootstrapContext, environment);DefaultPropertiesPropertySource.moveToEnd(environment);Assert.state(!environment.containsProperty(spring.main.environment-prefix),Environment prefix cannot be set via properties.);// 将所有spring.main 开头的配置信息绑定到SpringApplication中bindToSpringApplication(environment);if (!this.isCustomEnvironment) {EnvironmentConverter environmentConverter new EnvironmentConverter(getClassLoader());environment environmentConverter.convertEnvironmentIfNecessary(environment, deduceEnvironmentClass());}// 更新PropertySources配置ConfigurationPropertySources.attach(environment);return environment;}根据不同的web类型创建不同实现的Environment对象读取java环境变量和系统环境变量 ConfigurableEnvironment environment getOrCreateEnvironment();// 将命令行参数读取环境变量中 configureEnvironment(environment, applicationArguments.getSourceArgs());// 将PropertieSource的配置信息 放在第一位它的优先级是最低的 ConfigurationPropertySources.attach(environment);// 发布了ApplicationEnvironmentPreparedEvent的监听器读取了全局配置文件 listeners.environmentPrepared(bootstrapContext, environment);最终调用onApplicationEnvironmentPreparedEvent方法 步入postProcessEnvironment方法 步入processAndApply方法 步入applyToEnvironment方法 // 将所有spring.main 开头的配置信息绑定到SpringApplication中 bindToSpringApplication(environment);打印Banner // 打印Banner Banner printedBanner printBanner(environment);步入printBanner方法 步入print方法 步入getBanner方法 步入getTextBanner方法首先获取spring.banner.location的值如果没有就默认在根路径下输出banner.txt文件。 获取完banner后会输出 banner.printBanner(environment, sourceClass, out);步入该方法输出banner 创建上下文容器 // 据webApplicationType创建不同的Spring上下文容器有三种 context createApplicationContext();预初始化上下文容器 prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);步入prepareContext方法 首先获取所有ApplicationContextInitializer 循环调用initialize方法。 获取beanFactory。 对bean进行check如果有重复的bean就会抛出异常。 将启动类注册到Spring容器中。 刷新Spring容器 这里前几章文章重点讲的包括bean的加载、实例化、初始化、aop、事务、tomcat启动。 可以移步专栏查看 《Java系核心技术》 打印启动时间 Duration timeTakenToStartup Duration.ofNanos(System.nanoTime() - startTime);if (this.logStartupInfo) {new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), timeTakenToStartup);}发布事件 // 发布ApplicationStartedEvent事件和AvailabilityChangeEvent事件 listeners.started(context, timeTakenToStartup);最终来到这个方法进行事件的发布 最终进行发布 执行特定的run方法 // 获取Spring容器中的ApplicationRunner/CommandLineRunner类型的Bean,并执行run方法 callRunners(context, applicationArguments);ApplicationRunner和CommandLineRunner简介 后续就是发布ApplicationReadyEvent事件和AvailabilityChangeEvent事件以及对异常的处理。
http://www.yayakq.cn/news/4097/

相关文章:

  • 网站建设什么科目wordpress后台入口
  • 网站开发学什么好wordpress 获取文章链接
  • 青岛外贸网站推广收费小说网站怎么做
  • 网站分类模板网站域名解析ip
  • 保定网站建设兼职怀化建设局网站
  • 广告推销网站东莞企业网站多少钱
  • html移动网站开发国外 素材 网站
  • 个人网站备案怎么做免费wordpress
  • python搭建网站自己做的网页怎么发布
  • 网站建设意味着什么网站建设整体情况介绍
  • 网站怎么做构成网站开发前端模板
  • 潍坊 区网站建设国内有名室内设计公司
  • 快速网站备案中国购物网站有哪些
  • 优设网站怎么下载服务好的普通网站建设
  • 网站整体建设方案论文在什么网站可以做推广
  • 国外好玩的网站网站顶部轮播怎么做
  • 临沂做网站的2022年新闻热点事件
  • 网站推广四个阶段wordpress 全屏主题
  • 婚纱摄影网站定制seo优化网站建设哪家好
  • 网站建设时间计划图域名怎么绑定自己网站
  • 门户网站域名杭州建设工程协会
  • 企业网站托管费用现在 做网站 最流行
  • 网站后台管理怎么进电脑iis做网站
  • dedecms网站空白网站建设公司兴田德润i优惠吗
  • 海尔网站建设目标深圳甜富设计
  • 河源市住房建设局网站wordpress回复查看插件
  • iis网站重定向沈阳网上注册公司流程
  • 网站建设空间步骤详解福田做棋牌网站建设哪家技术好
  • 东莞网站开发报价个人网站开发背景及意义
  • 典当行网站策划凡客诚品官网app下载