springboot 项目一启动,就开始运行某个功能:实现 CommandLineRunner 接口,重写 run 方法。

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

猜你喜欢

转载自blog.csdn.net/beguile/article/details/88069451