监听器

Springboot 2启动源码流程

匿名 (未验证) 提交于 2019-12-02 21:52:03
以使用静态方法 SpringApplication.run(Bootstrap.class, args) 启动 Springboot 为例,启动流程主要分为 SpringApplication 的创建和运行两部分; 设置资源加载器,此处为空 设置 Springboot 启动类 根据类路径判断 web 类型,默认为 SERVLET->Spring MVC 读取每个 jar 包的 /META-INF/spring.factories 文件,获取 key 为 org.springframework.context.ApplicationContextInitializer 的值,即初始化器 读取每个 jar 包的 /META-INF/spring.factories 文件,获取 key 为 org.springframework.context.ApplicationListener 的值,即监听器 从当前的运行时堆栈元素中,找到 main 方法所在类 启动计时秒表 读取每个 jar 包的 /META-INF/spring.factories 文件,获取 key 为 org.springframework.boot.SpringApplicationRunListener 的值,即 Springboot 的运行监听器,默认有 EventPublishingRunListener

Springboot 2使用SpringApplication

匿名 (未验证) 提交于 2019-12-02 21:52:03
SpringApplication 使用静态方法 SpringApplication.run(MySpringConfiguration.class, args); 使用构造器 SpringApplication app = new SpringApplication(MySpringConfiguration.class); app.setBannerMode(Banner.Mode.OFF); app.run(args); 使用 builder new SpringApplicationBuilder(Application.class) .bannerMode(Banner.Mode.OFF) .run(args); 初始化实现了 FailureAnalyzer 接口的失败分析器,可以在启动失败时,打印错误日志和解决操作方法。比如启动端口被占用时打印如下日志: 2019-08-07 10:22:32.534 ERROR 2616 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: The Tomcat connector

Spring事件监听器源码

匿名 (未验证) 提交于 2019-12-02 21:52:03
Spring 自定义了继承 JDK 事件监听器的接口 ApplicationListener<E extends ApplicationEvent> extends EventListener ,用来监听 Spring 应用程序中的事件;自定义了继承 JDK 事件对象的抽象类 ApplicationEvent extends EventObject ,用来表示 Spring 应用程序中的事件类型。容器启动刷新过程中,可以定义事件监听器,来监听应用程序上下文事件 ApplicationContextEvent extends ApplicationEvent ,它有四个具体的实现类: ContextStartedEvent/ContextRefreshedEvent/ContextStoppedEvent/ContextClosedEvent ,分别表示容器启动/刷新/停止/关闭的事件。 通常有两种方式来实现 Spring 中的事件监听: 1.实现 ApplicationListener 接口 public class MyListener implements ApplicationListener<ApplicationEvent> { @Override public void onApplicationEvent(ApplicationEvent event) {

JavaWeb-其他Listener监听器(2)

匿名 (未验证) 提交于 2019-12-02 21:52:03
感知Session绑定的事件监听器 * 保存在Session域中的对象可以有多种状态: 持久化 到一个存储设备中;(2)随Session对象从一个存储设备中 恢复 。 * Servlet定义两个接口帮助 JavaBean 对象 了解自己在Session域中的这些状态 :   HttpSessionBindingListener接口和HttpSessionActivationListener接口    实现这两个接口的类不需要web.xml文件中进行注册 HttpSessionBingdingListener接口 * 实现了 HttpSessionBingdingListener接口的JavaBean对象可以感知自己被绑定到Session中和从Session中删除的事件 * 当对象被绑定到HttpSession对象中时,web服务器调用该对象的void valueBound(HttpSessionBindingEvent event)方法 * 当对象从HttpSession对象中解除绑定时,web服务器调用该对象的void valueUnbound(HttpSessionBindingEvent event)方法 HttpSessionBindingEvent: getName() getValue() getSession() 该监听器较少被调用

Servlet八大监听器

匿名 (未验证) 提交于 2019-12-02 20:41:15
监听器的分类 监听域对象自身创建和销毁的监听器: ①ServletContextListener接口 监听 SercvletContext 对象 ②HttpSessionListener接口 监听 HttpSession 对象 ③ServletRequestListener接口 监听 ServletRequest 对象 监听域对象中的属性的增加、修改和删除的事件监听器 对象属性 ⑤HttpSessionAttributeListener接口 监听 HttpSession 对象属性 ⑥ServletRequestAttributeListener接口 监听 ServletRequest 对象属性 监听绑定到 HttpSession 域中某个对象的状态的事件监听器 ⑦HttpSessionBindingListener接口 监听 实现了HttpSessionBindingListener接口的对象的session绑定和解除 ⑧HttpSessionActivationListener接口 (实现会话的持久化) 监听器的包含类及其作用 ①ServletContextListener 相关方法 contextInitialized(ServletContextEvent arg0):在Web应用加载的时候被调用 contextDestroyed(ServletContextEvent

监听器统计当前在线人数

和自甴很熟 提交于 2019-12-02 14:29:24
OnlineListener 实现接口HttpSessionListener package listener ; import javax . servlet . ServletContext ; import javax . servlet . http . HttpSessionEvent ; import javax . servlet . http . HttpSessionListener ; public class Online Listener implements HttpSessionListener { @Override public void sessionCreated ( HttpSessionEvent e ) { ServletContext application = e . getSession ( ) . getServletContext ( ) ; Integer online_number = ( Integer ) application . getAttribute ( "online_number" ) ; if ( null == online_number ) online_number = 0 ; online_number ++ ; application . setAttribute ( "online_number"

webpack4.0各个击破(8)—— tapable篇

∥☆過路亽.° 提交于 2019-12-02 14:01:16
webpack 作为前端最火的构建工具,是前端自动化工具链 最重要的部分 ,使用门槛较高。本系列是笔者自己的学习记录,比较基础,希望通过 问题 + 解决方式 的模式,以前端构建中遇到的具体需求为出发点,学习 webpack 工具中相应的处理办法。(本篇中的参数配置及使用方式均基于 webpack4.0版本 ) 一. tapable概述 tapable 地址: 【tapable-0.2】 tapable 是 webpack 的核心框架(4.0以上版本的API已经发生了变化),是一个基于事件流的框架,或者叫做发布订阅模式,或观察者模式, webpack 的整个生命周期及其开放的自定义插件系统都离不开 tapable 的支持,研究其运行原理是阅读 webpack 源代码的第一步。官方仓库 master 分支的代码是经过ES6重构的,模块化拆分非常细,且加入了很多非核心逻辑,阅读难度较大。建议先从官方仓库中0.2版本的分支开始学习,整个源码只有400行,相对容易理解。 二. tapable-0.2源码解析 2.1 代码结构 //类定义 function Tapable() { this._plugins = {}; } //模块导出 module.exports = Tapable; //定义了许多内部方法和原型方法 ... Tapable 实际上就是一个类定义的模块。 2.2

ListenerBus 事件总线

喜欢而已 提交于 2019-12-02 11:44:55
ListenerBus 事件总线 ListenerBus可以接收事件并将事件送到对应的事件监听器 源码清单和我的理解注释 ListenerBus源码中第一行,创建了一个线程安全的ArrayList——CopyOnWriteArrayList,之后添加、者删除事件等操作都在这个线程安全的ArrayList中执行 private [ spark ] val listeners = new CopyOnWriteArrayList [ L ] private [ spark ] trait ListenerBus [ L < : AnyRef , E ] extends Logging { // 创建一个线程安全的ArrayList private [ spark ] val listeners = new CopyOnWriteArrayList [ L ] /** * 往CopyOnWriteArrayList中添加监听器 */ final def addListener ( listener : L ) : Unit = { listeners . add ( listener ) } /** * 在CopyOnWriteArrayList删除监听器 */ final def removeListener ( listener : L ) : Unit = { listeners

RabbitMQ学习笔记:addReturnListener监听回退消息

半世苍凉 提交于 2019-12-02 10:41:38
发布消息示例 channel . basicPublish ( EXCHANGE_NAME , ROUTING_KEY , true , false , properties . build ( ) , message . getBytes ( ) ) ; 参数: mandatory:如果为true, 消息不能路由到指定的队列时,则会调用basic.return方法将消息返回给生产者,会触发addReturnListener注册的监听器;如果为false,则broker会直接将消息丢弃 immediate:如果为true,当exchange将消息路由到queue时发现queue上没有消费者,那么这条消息不会放入队列中,该消息会通过basic.return方法返还给生产者。 在RabbitMQ3.0以后的版本里去掉了immediate参数的支持,发送带immediate=true的publish会返回如下错误, com.rabbitmq.client.AlreadyClosedException: connection is already closed due to connection error; protocol method: #method<connection.close>(reply-code=540, reply-text=NOT_IMPLEMENTED -

手动实现一个监听器,监听队列的出入队(一)

喜夏-厌秋 提交于 2019-12-02 08:56:05
1、java中的监听器时啥? 监听器是一种特殊的类,当程序中执行了某项特殊的操作时会导致这个类执行一些操作,这些操作称之为事件。 2、监听器的用途 用途广泛,用于指定情况发生后的处理操作,如在线人数的统计,每一个用户登录成功都触发一次监听器对在线人数 + 1 3、实现 监听器接口 /** * * @ClassName: IListener * @Description: 定义事件监听器接口,所有的事件监听器都需要实现该接口 * @Author pengdehe * @DateTime 2019年10月25日 下午4:10:25 */ public interface IListener { /** * * @Title: doEvent * @Description: 触发监听器后执行的操作 * @Author Administrator * @DateTime 2019年10月25日 下午4:15:55 * @param event */ void doEvent ( IEvent event ) ; } 事件接口 /** * * @ClassName: IEvent * @Description: 定义事件接口,所以的事件源都需要实现该接口 * @Author pengdehe * @DateTime 2019年10月25日 下午4:08:30 */ public