zoukankan      html  css  js  c++  java
  • springboot-事件

    @SpringBootApplication
    public class SpringbootdemoApplication {
    
        public static void main(String[] args) {
    
            new SpringApplicationBuilder(SpringbootdemoApplication.class)
                   
                    .listeners(event -> {
                        System.out.println("监听到事件:" + event.getClass().getName());
                    })
                    .run(args)
                    .close();
        }
    
    }

    输出结果:

    监听到事件:org.springframework.boot.context.event.ApplicationStartingEvent(1)
    监听到事件:org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent(2)

    监听到事件:org.springframework.boot.context.event.ApplicationContextInitializedEvent

    监听到事件:org.springframework.boot.context.event.ApplicationPreparedEvent(3)

    监听到事件:org.springframework.context.event.ContextRefreshedEvent

    监听到事件:org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent

    监听到事件:org.springframework.boot.context.event.ApplicationStartedEvent(4)

    监听到事件:org.springframework.boot.context.event.ApplicationReadyEvent(5)

    监听到事件:org.springframework.context.event.ContextClosedEvent

    (6) ApplicationFailedEvent 特殊情况

    以上6种是springboot的事件。

    ConfigFileApplicationListener监听ApplicationEnvironmentPreparedEvent事件,从而加载application.properties或

    application.yml文件

    springboot很多组件依赖于springboot事件监听器实现,本质是spring framework事件监听机制

    SpringApplication利用

      spring应用上下文(ApplicationContext)生命周期控制注解驱动bean

      spring事件/监听机制(ApplicationEventMulticaster)加载或初始化组件

  • 相关阅读:
    java se 转到ee小结
    objective c基本知识
    2013_11_14:递归算法(2)—全排列
    2013_11_13:递归算法(1)
    2013_11_13:关于 new 和delelte 的使用
    c++调试问题
    模式匹配BM算法介绍与实现
    一个n数组求和问题
    机试题
    算法题目
  • 原文地址:https://www.cnblogs.com/yintingting/p/6574693.html
Copyright © 2011-2022 走看看