Spring boot 는 CommandLine Runner 를 통 해 시작 완료 후 작업 을 수행 합 니 다.
실현 하 는 방법 은 여러 가지 가 있 습 니 다. 오늘 저희 가 소개 한 것 은 CommandLine Runner 를 통 해 이 루어 지 는 것 입 니 다.
@Component
@Order(value = 1) // ,
public class MyRunner1 implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("MyRunner1");
}
}
@Component
@Order(value = 2) // ,
public class MyRunner2 implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("MyRunner2");
}
}
결 과 는 다음 과 같 습 니 다. 두 작업 은 MyApplication 이 시 작 된 후에 실행 되 고 MyRunner 1 이 먼저 실 행 됩 니 다.
2020-08-21 15:21:49.169 custom-logback INFO 19368 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 88888 (http) with context path ''
2020-08-21 15:21:49.177 custom-logback INFO 19368 --- [ main] com.yeyuanxinyi.MyApplication : Started MyApplication in 14.903 seconds (JVM running for 19.368)
MyRunner1
MyRunner2
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[MeU] Hashtag 기능 개발➡️ 기존 Tag 테이블에 존재하지 않는 해시태그라면 Tag , tagPostMapping 테이블에 모두 추가 ➡️ 기존에 존재하는 해시태그라면, tagPostMapping 테이블에만 추가 이후에 개발할 태그 기반 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.