Spring容器扩展及其他记录

本文详细探讨了Spring Boot中上下文扩展ApplicationContextAware的使用,初始化与销毁行为的InitializingBean与DisposableBean,以及实例加载过程中的SmartInitializingSingleton。还涉及方法上下文的MethodIntrospector在XxlJob中的应用,展示了如何通过注解查找相关方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.上下文扩展  ApplicationContextAware

Map<String,  XXXXTask> ywwlTaskMap = applicationContext.getBeansOfType( XXXXTask.class);
xxxxTaskMap.forEach((x, y) -> {
    XXXXTaskName ywwlTaskName = y.getClass().getAnnotation( XXXXTaskName.class);
    //判断是否实现了ywwltaskname注释
    if (ywwlTaskName!= null) {
        String taskName = ywwlTaskName.taskName();
        
        };
    }
});

2. init与destroy方法:InitializingBean(init)  DisposableBean(销毁)

3.实例加载完毕扩展:SmartInitializingSingleton

4.方法上下文:MethodIntrospector

Map<Method, XxlJob> annotatedMethods = null;   // referred to :org.springframework.context.event.EventListenerMethodProcessor.processBean
try {
    annotatedMethods = MethodIntrospector.selectMethods(bean.getClass(),
            new MethodIntrospector.MetadataLookup<XxlJob>() {
                @Override
                public XxlJob inspect(Method method) {
                    return AnnotatedElementUtils.findMergedAnnotation(method, XxlJob.class);
                }
            });
} catch (Throwable ex) {
    logger.error("xxl-job method-jobhandler resolve error for bean[" + beanDefinitionName + "].", ex);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值