CommandLineRunner
发布日期:2021-06-28 23:30:20 浏览次数:4 分类:技术文章

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

@

CommandLineRunner不是Spring框架原有的“宝贝”,它属于SpringBoot应用特定的回调扩展接口

public interface CommandLineRunner {
void run(String... args) throws Exception;}

CommandLineRunner需要大家关注的其实就两点:

1)所有CommandLineRunner的执行时点在SpringBoot应用的Application-Context完全初始化开始工作之后(可以认为是main方法执行完成之前最后一步)。

2)只要存在于当前SpringBoot应用的ApplicationContext中的任何Command-LineRunner,都会被加载执行(不管你是手动注册这个CommandLineRunner到IoC容器,还是自动扫描进去的)。

与其他几个扩展点接口类型相似,建议CommandLineRunner的实现类使用@org.springframework.core.annotation.Order进行标注或者实现org.springframework.core.Ordered接口,便于对它们的执行顺序进行调整,这其实十分重要,我们不希望顺序不当的CommandLineRunner实现类阻塞了后面其他CommandLineRunner的执行。

CommandLineRunner是很好的扩展接口,大家可以重点关注,我们在后面的扩展和微服务实践章节会再次遇到它。

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

上一篇:纷杂的spring-boot-starter
下一篇:ApplicationContextInitializer

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月07日 18时37分14秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章