Springboot

1.实现方式

  1. 实现ApplicationRunner接口
  2. 实现CommandLineRunner接口
    @Component
    @Slf4j
    public class AfterServiceStarted implements ApplicationRunner{
    
        /**
         * 会在服务启动完成后立即执行
         */
        @Override
        public void run(ApplicationArguments args) throws Exception {
    
            log.info("Successful service startup!");
        }
    }
    @Component
    public class AfterServiceStartedOther implements CommandLineRunner{
    
        /**
         * 会在服务启动完成后立即执行
         */
        @Override
        public void run(String... args) throws Exception {
    
            JedisSingleton.getInstance().set("Service startup time", String.valueOf(System.nanoTime()));
        }
    }
原文地址:https://www.cnblogs.com/Mr-Rocker/p/9887695.html