Spring 服务启动 自动执行(ApplicationListener)
发布日期:2022-01-11 03:09:58 浏览次数:11 分类:技术文章

本文共 609 字,大约阅读时间需要 2 分钟。

import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.ApplicationListener;import org.springframework.context.event.ContextRefreshedEvent;import org.springframework.stereotype.Service;/** *  * @author yuki_ho * */@Servicepublic class StartAddDataListener implements ApplicationListener
{ @Override public void onApplicationEvent(ContextRefreshedEvent event) { if(event.getApplicationContext().getParent() == null)//root application context 没有parent,他就是老大. { //需要执行的逻辑代码,当spring容器初始化完成后就会执行该方法。 } }}

转载地址:https://yuki-ho.blog.csdn.net/article/details/53518145 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Spring4 实战笔记(1):装配bean—依赖注入的本质
下一篇:CXF客户端(动态调用)

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年03月31日 09时16分59秒