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

做公司网站有什么猫腻seo网站推广方案

做公司网站有什么猫腻,seo网站推广方案,品牌网站建设小蝌蚪2a,服装行业网站建设从监听器到事件 SpringApplication运行中触发事件,多播器发送事件到监听器,监听器处理事件。 SpingApplication中事件都是经过SpringApplicationRunListeners类传送到各个监听器。 以starting事件为例 void starting(ConfigurableBootstrapContext boo…

从监听器到事件

SpringApplication运行中触发事件,多播器发送事件到监听器,监听器处理事件。
SpingApplication中事件都是经过SpringApplicationRunListeners类传送到各个监听器。
以starting事件为例

void starting(ConfigurableBootstrapContext bootstrapContext, Class<?> mainApplicationClass) {doWithListeners("spring.boot.application.starting", (listener) -> listener.starting(bootstrapContext),(step) -> {if (mainApplicationClass != null) {step.tag("mainApplicationClass", mainApplicationClass.getName());}});
}
private void doWithListeners(String stepName, Consumer<SpringApplicationRunListener> listenerAction,Consumer<StartupStep> stepAction) {StartupStep step = this.applicationStartup.start(stepName);this.listeners.forEach(listenerAction);if (stepAction != null) {stepAction.accept(step);}step.end();
}

这里的this.listeners是一个SpringApplicationRunListener的集合,而SpringApplicationRunListener的实现类配置中只有一个EventPublishingRunListener
starting事件执行的是EventPublishingRunListenerstarting方法

public void starting(ConfigurableBootstrapContext bootstrapContext) {this.initialMulticaster.multicastEvent(new ApplicationStartingEvent(bootstrapContext, this.application, this.args));
}

这里就找到了第一个事件ApplicationStartingEvent
接着往下执行

public void multicastEvent(ApplicationEvent event) {multicastEvent(event, resolveDefaultEventType(event));
}@Override
public void multicastEvent(final ApplicationEvent event, @Nullable ResolvableType eventType) {ResolvableType type = (eventType != null ? eventType : resolveDefaultEventType(event));Executor executor = getTaskExecutor();for (ApplicationListener<?> listener : getApplicationListeners(event, type)) {if (executor != null) {executor.execute(() -> invokeListener(listener, event));}else {invokeListener(listener, event);}}
}

ResolvableType类这里略过,里面涉及的内容较多,在这里的具体作用是从类的注解、泛型、继承结构、代理上获取原始的目标对象。
这里要注意的方法getApplicationListeners,根据事件类型获取监听器,然后执行。
查找的过程比较长,这里列举一些比较重要的方法
AbstractApplicationEventMulticastergetApplicationListenersretrieveApplicationListenerssupportsEvent
supportsEvent方法中有具体的判断逻辑

protected boolean supportsEvent(ApplicationListener<?> listener, ResolvableType eventType, @Nullable Class<?> sourceType) {GenericApplicationListener smartListener = (listener instanceof GenericApplicationListener ?(GenericApplicationListener) listener : new GenericApplicationListenerAdapter(listener));return (smartListener.supportsEventType(eventType) && smartListener.supportsSourceType(sourceType));
}

根据监听器的类型调用监听器类的支持事件类型supportsEventType和支持事件源类型supportsSourceType两个方法,来判断是否传播到该监听器。
ApplicationListener监听器有多个实现。

  • ClearCachesApplicationListener
  • ParentContextCloserApplicationListener
  • FileEncodingApplicationListener
  • AnsiOutputApplicationListener
  • DelegatingApplicationListener
  • LoggingApplicationListener
  • EnvironmentPostProcessorApplicationListener
  • BackgroundPreinitializer

ClearCachesApplicationListener

结构:
implements ApplicationListener<ContextRefreshedEvent>
支持的事件类型:

  • ContextRefreshedEvent
  • ApplicationContextEvent
  • ApplicationEvent

支持的事件源:
无限制

ParentContextCloserApplicationListener

结构:
implements ApplicationListener<ParentContextAvailableEvent>, ApplicationContextAware, Ordered
支持的事件类型

  • ParentContextAvailableEvent
  • ApplicationEvent

支持的事件源:
无限制

FileEncodingApplicationListener

结构:
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered
支持的事件类型:

  • ApplicationEnvironmentPreparedEvent
  • SpringApplicationEvent
  • ApplicationEvent

支持的事件源:
无限制

AnsiOutputApplicationListener

结构:
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered
支持的事件类型:

  • ApplicationEnvironmentPreparedEvent
  • SpringApplicationEvent
  • ApplicationEvent

支持的事件源:
无限制

DelegatingApplicationListener

结构:
implements ApplicationListener<ApplicationEvent>, Ordered
支持的事件类型:

  • ApplicationEvent

支持的事件源:
无限制

LoggingApplicationListener

结构:
implements GenericApplicationListener
支持的事件类型:

  • ApplicationStartingEvent
  • ApplicationEnvironmentPreparedEvent
  • ApplicationPreparedEvent
  • ContextClosedEvent
  • ApplicationFailedEvent

支持的事件源:

  • SpringApplication
  • ApplicationContext

EnvironmentPostProcessorApplicationListener

结构:
implements SmartApplicationListener, Ordered
支持的事件类型:

  • ApplicationEnvironmentPreparedEvent
  • ApplicationPreparedEvent
  • ApplicationFailedEvent

支持的事件源:

  • SpringApplication
  • ApplicationContext

BackgroundPreinitializer

结构:
implements ApplicationListener<SpringApplicationEvent>
支持的事件类型:

  • SpringApplicationEvent
  • ApplicationEvent

支持的事件源:
无限制

事件

EventPublishingRunListener的方法还有上面的事件类型,SpringBoot中的事件类型有:

  • ApplicationStartingEvent
  • ApplicationEnvironmentPreparedEvent
  • ApplicationContextInitializedEvent
  • ApplicationPreparedEvent
  • ApplicationStartedEvent
  • ApplicationReadyEvent

除了multicastEvent多播事件,还有下面两个方法发布事件。

@Override
public void started(ConfigurableApplicationContext context, Duration timeTaken) {context.publishEvent(new ApplicationStartedEvent(this.application, this.args, context, timeTaken));AvailabilityChangeEvent.publish(context, LivenessState.CORRECT);
}@Override
public void ready(ConfigurableApplicationContext context, Duration timeTaken) {context.publishEvent(new ApplicationReadyEvent(this.application, this.args, context, timeTaken));AvailabilityChangeEvent.publish(context, ReadinessState.ACCEPTING_TRAFFIC);
}

事实上,这些事件都在一个包路径下。
在这里插入图片描述

ApplicationStartingEvent

注释:

事件在启动SpringApplication后尽早发布——在Environment或ApplicationContext可用之前,但在ApplicationListeners注册之后。事件的来源是SpringApplication本身,但要注意在早期阶段不要过多地使用其内部状态,因为它可能会在生命周期的后期被修改。

使用的翻译,不甚明了,得看看怎么这个事件触发后,监听器做了什么。

ApplicationEnvironmentPreparedEvent

注释:

当SpringApplication启动并且环境首次可用于检查和修改时发布的事件

ApplicationContextInitializedEvent

注释:

在启动SpringApplication、准备ApplicationContext和调用ApplicationContextInitializer时发布的事件,但在加载任何bean定义之前。

ApplicationPreparedEvent

注释:

当SpringApplication正在启动并且ApplicationContext已完全准备好但未刷新时发布的事件。将加载bean定义,并且环境已准备好在此阶段使用

ApplicationStartedEvent

注释:

刷新应用程序上下文后,但在调用任何应用程序和命令行运行程序之前发布的事件

ApplicationReadyEvent

注释:

事件尽可能晚地发布,以指示应用程序已准备好为请求提供服务。事件的来源是SpringApplication本身,但要注意修改其内部状态,因为届时所有初始化步骤都已完成

ApplicationFailedEvent

注释:

SpringApplication在启动失败时发布的事件

http://www.hengruixuexiao.com/news/54767.html

相关文章:

  • 玉泉营网站建设网站被百度收录
  • 汶上1500元网站建设百度扫一扫识别图片在线
  • 青岛网站建设多少钱百度一下浏览器下载安装
  • 如何做vip影视网站关键词优化排名软件哪家好
  • 自己的网站怎么做网盘什么是seo推广
  • 做字幕模板下载网站神马网站快速排名软件
  • 官方网站建设银行年利息是多少福建seo快速排名优化
  • 哪些网站做外链好互联网营销师考证多少钱
  • 百度网站评级台州网站建设推广
  • 网站的评测系统怎么做的年度关键词
  • 企业建站免费seo搜索优化
  • 杭州自助建站模板南宁seo收费
  • 购物类型网站建设百度搜索引擎优化方式
  • 石家庄哪有个人建站的百度移动排名优化软件
  • 泉州微信网站开发保定百度seo排名
  • 网站工作室网站奶糖 seo 博客
  • 自己电脑做网站访问速度可以推广的平台
  • 重庆做网站找谁长沙网红奶茶
  • 专业武汉网站建设公司最新新闻热点素材
  • 两学一做 专题网站长沙百度提升排名
  • 秦皇岛网站推广报价seo技术培训广东
  • 做301跳转会影响之前网站排名吗百度搜索排名与点击有关吗
  • 九江网站开发公司淘宝关键词排名查询网站
  • 北京丰台住房和城乡建设委员会网站查企业信息查询平台
  • 传播型网站建设优势有哪些水果网络营销推广方案
  • 成都个人网站建设自己怎么注册网站
  • 六安网络科技有限公司seo推广怎么收费
  • 高端网站开发注意事项广州百度竞价外包
  • 如何自己建设淘宝网站首页优化网络
  • 1000学习做网站贵吗武汉百度推广优化