在Springboot程序启动时往往需要执行响应的任务,我们可以通过实现CommandLineRunner接口重写run方法达到对应的效果:
@Component
@Order(value=1)
//order为启动执行顺序
public class StartRunner implements CommandLineRunner {
private static final Logger LOGGER = LoggerFactory.getLogger(StartRunner.class);
@Override
public void run(String... args) throws Exception {
//代码块
}
}
最后
以上就是爱笑冥王星最近收集整理的关于Springboot启动时执行任务CommandLineRunner的全部内容,更多相关Springboot启动时执行任务CommandLineRunner内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复