spring容器事件机制
所属分类 spring
浏览量 1041
事件监听
事件类型 java.util.EventObject
事件监听器 java.util.EventListener
Spring容器事件监听机制
事件类型
org.springframework.context.AppliationEvent
监听器
org.springframework.context.ApplicationListener
public interface ApplicationListener extends EventListener {
void onApplicationEvent(E event);
}
Spring 内置事件
ContextRefreshedEvent
ContextStartedEvent
ContextStoppedEvent
ContextClosedEvent
RequestHandledEvent
@Component
public class MyApplicationListener implements ApplicationListener< ApplicationEvent>{
@Override
public void onApplicationEvent(ApplicationEvent event){
System.out.println("onApplicationEvent,"+event+","+Thread.currentThread());
}
}
ApplicationContext容器 发布事件
AbstractApplicationContext.publishEvent(ApplicationEvent event)
SimpleApplicationEventMulticaster
@EventListener
自定义事件实例
https://gitee.com/dyyx/springboothello/tree/master/src/main/java/demo/event
上一篇
下一篇
Springboot监控端点Actuator实例
SpringIoC容器要点
JavaConfig与常见的Annotation
SpringFactoriesLoader 简介
Springboot自动配置原理简介
spring security 模块简介