springBoot启动时执行

开发的时候需要项目启动后执行一些初始化功能,soringBoot中可以添加一个model并实现CommandLineRunner接口,实现功能的代码放在实现的run方法中

package org.springboot.sample.runner;

import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component //作为bean加入spring
@Order(value=2)//多个启动任务的执行顺序
public class MyStartupRunner1 implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        System.out.println(">>>>>>>>>>>>>>>服务启动执行 2222 <<<<<<<<<<<<<");
    }
}

转载于:https://www.jianshu.com/p/4495f0663e25

猜你喜欢

转载自blog.csdn.net/weixin_33922672/article/details/91171889