定义一个类实现ApplicationRunner
接口,然后Override这个ApplicationRunner
接口的run方法
@Component public class TaskRunner implements ApplicationRunner { public static final Logger log = LoggerFactory.getLogger(TaskRunner.class); @Override public void run(ApplicationArguments args) throws Exception { //初始化 } }