参考:https://blog.csdn.net/u010349272/article/details/108028504

一,ApplicationRunner 接口

  1. @Component
  2. public class Runner implements ApplicationRunner {
  3. @Autowired
  4. private ZkUserService zkUserService;
  5. @Override
  6. public void run(ApplicationArguments args) throws Exception {
  7. System.out.println("===============");
  8. }
  9. }

二,CommandLineRunner 接口

  1. @Component
  2. public class Runner implements CommandLineRunner {
  3. @Autowired
  4. private ZkUserService zkUserService;
  5. @Override
  6. public void run(String... args) throws Exception {
  7. System.out.println("===============");
  8. }
  9. }