Spring boot+Vue全栈开发---启动系统任务

有些工作需要在系统启动的时候就开始,比如配置文件的加载,或者数据库的初始化等等。spring boot提供了CommandLineRunner、ApplicationRunner两个解决方案

通过CommandLineRunner配置

通过继承CommandLineRunner类并重写Run方法可以实现系统启动时候的任务启动。多个类继承了CommandLineRunner均不影响各自的执行。可以通过@Order(n)来标记执行次序。

Spring boot+Vue全栈开发---启动系统任务

 

通过ApplicationRunner配置

继承ApplicationRunner类并重写Run方法

参数类型是ApplicationArguments

args.getNonOptionArgs()获取命令行参数

getOptionNames()获取参数名

getOptionValues()获取参数值

Spring boot+Vue全栈开发---启动系统任务