Springboot - 시작 후 특정 코드 실행

Springboot - 시작 후 특정 코드 실행


1. 실현 방식
  • ApplicationRunner 인터페이스 구현
  • CommandLineRunner 커넥터 구현
  • 2. 코드
    @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()));
        }
    }
    

    좋은 웹페이지 즐겨찾기