Java 自动执行任务
作者:互联网
实现一:实现ApplicationRunner接口
@Component public class MyApplicationRunner implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { System.out.println("MyApplicationRunner自动执行任务"); } }
实现二:实现CommandLineRunner接口
@Component @Order(0) public class MyCommandRunner implements CommandLineRunner { @Override public void run(String... args) throws Exception { System.out.println("MyCommandRunner自动执行任务"); } }
调节自动任务的顺序加@Order注解 ,值越小优先级越高
标签:Java,System,任务,自动,Override,ApplicationRunner,public,out 来源: https://www.cnblogs.com/younger5/p/15841808.html