spring ApplicationContext

spring ApplicationContext有五种标准事件

1 ContextRefreshedEvent:当ApplicationContext初始化或者刷新时触发该事件。

2 ContextClosedEvent:当ApplicationContext被关闭时触发该事件。容器被关闭时,其管理的所有单例Bean都被销毁。

3 RequestHandledEvent:在Web应用中,当一个http请求(request)结束触发该事件。

4 ContestStartedEvent:ConfigurableApplicationContext的Start()方法开始/重新开始容器时触发该事件。

5 ContestStopedEvent:ConfigurableApplicationContext的Stop()方法停止容器时触发该事件。

MyApplicationListener

MyApplicationListener实现了ApplicationListener接口

监听ApplicationContext事件onApplicationEvent方法对ApplicationContext的初始化或刷新做出反应

 

MyRejectedExecutionHandler

MyRejectedExecutionHandler实现了RejectedExecutionHandler接口

public void rejectedExecution(Runnable r,ThreadPoolExecutor executor)方法

当我们创建线程池并且提交任务失败时,线程池会回调RejectedExecutionHandler接口的rejectedExecution(Runnabletask, ThreadPoolExecutor executor)方法来处理线程池处理失败的任务,其中r 是用户提交的任务,而executor是当前执行的任务的线程池。可以通过代码的方式来验证。

 

SpringHelper

SpringHelper实现了ApplicationContextAware接口

实现了ApplicationContextAware接口就可以获得spring容器中的所有bean类,通过setApplicationContext方法获取ApplicationContext对象,当实现了这个接口并且将这个类注册成bean的时候,在spring启动的时候会带调用setApplicationContext方法。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值