작업을 호출하지 않고 모든 로직을 수행하는 어플리케이션을 만들기 위해서 공부하다가 알게 되었다.
application실행 시에 동작을 할 수 있는 것이 ApplictionRunner와 CommandLineRunner 두가지가 있다.
차이점은 ApplicationRunner는 단순 인자의 스트링 배열을 포함한 추상화한 ApplicationArguments 타입의 객체가 Run()메소드의 인자로 넘어오고 CommandLineRunner는 기본적인 Array 형태로 argument가 Run()메소드의 인자로 넘어온다.
CommandLineRunner란?
특정 Bean을 Application 실행 후 실행하도록 하는 인터페이스이다. 이는 ApplicationRunner도 같다. 클래스로 구현해서 사용해야 한다.
CommandLineRunner bean을 여러개 만들 수 있기 때문에 @Order을 사용하여 순서를 정할 수 있다.
만약에 ApplicationArguments를 문자열 대신에 사용한다면 ApplicationRunner를 사용하는 것이 낫다.
[CommandLineRunner]

[ApplicationRunner]

[참고자료]
https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/CommandLineRunner.html
CommandLineRunner (Spring Boot 2.6.0 API)
docs.spring.io
https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/ApplicationRunner.html
ApplicationRunner (Spring Boot 2.6.0 API)
docs.spring.io
'Weekly I Learnd' 카테고리의 다른 글
[W.I.L]ThreadPoolExecutor (0) | 2021.11.28 |
---|---|
[WIL] test code /spring webflux /가짜 중복,진짜 중복 (0) | 2021.11.06 |
[W.I.L] 개인공부 (0) | 2021.06.28 |
[W.I.L] 15주차 모의면접 주차(feat. 항해99 마지막 주차) (0) | 2021.06.06 |
[W.I.L]13주차 (실전프로젝트 5주차)(feat.항해99) (0) | 2021.05.30 |