import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class MyStartupRunner implements CommandLineRunner {
// 项目启动后,就执行的功能
public void run(String... a) throws Exception{
while(true){
System.out.println("服务启动就执行的功能");
Thread.sleep(3000);
}
}
}
实现 CommandLineRunner 接口,重写 run 方法。
参考: www.cnblogs.com/myblogs-miller/p/9046425.html
本文介绍如何在SpringBoot项目中使用CommandLineRunner接口实现项目启动后自动执行特定任务的方法。通过创建一个实现CommandLineRunner接口的组件,可以在应用启动时运行自定义的代码逻辑,例如打印消息或初始化数据。
1664

被折叠的 条评论
为什么被折叠?



