CommandLineRunner或ApplicationRunner接口

本文详细解析了Spring框架中CommandLineRunner和ApplicationRunner接口的作用及差异。CommandLineRunner在容器启动后执行,可按order顺序批量运行;ApplicationRunner则接收ApplicationArguments参数,提供更高级的参数处理。

前言

CommandLineRunner和ApplicationRunner接口是在容器启动成功后的最后一步回调。

CommandLineRunner接口

接口被用作将其加入spring容器中时执行其run方法,多个CommandLineRunner可以被同时执行在同一个spring上下文中并且捃顺序是以order注解的参数顺序一致。

ApplicationRunner接口

以上面接口的javadoc一样,区别在于接收的参数不一样。CommandLineRunner参数是最原始的参数,没有做任何处理。ApplicationRunner的参数是ApplicationArguments,是对原始参数做了进一步封装。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值