springboot启动后,执行初始化任务

mac2024-05-11  35

1. 方式一

/** * Desc: 系统启动完可以做一些业务操作 */ @Component //如果有多个runner需要指定一些顺序 @Order(1) public class SimosApplicationRunner implements ApplicationRunner { @Autowired SystemInitService systemInitService; @Override public void run(ApplicationArguments args) throws Exception { systemInitService.systemInit(); } }

2. 方式二

import java.util.Arrays; import org.springframework.boot.CommandLineRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @Component @Order(2) public class MyCommandLineRunner implements CommandLineRunner { @Override public void run(String... args) throws Exception { // TODO Auto-generated method stub System.out.println("====================MyCommandLineRunner================"); System.out.println("order值: 2"); System.out.println("原始参数: " Arrays.asList(args)); System.out.println("======================================================="); }

本文由博客一文多发平台 OpenWrite 发布!

最新回复(0)