1. 모든 작업을 마치고 나서 "초기화 코드"를 넣어야 하는 경우
스프링부트 애플리케이션이 시작할 때 백그라운드에서 굉장히 많은 스프링 빈(Bean)들이 만들어지고 그 외에 스프링 컨테이너가 초기화하는 과정이 진행된다.
2. 초기화와 동시에 스프링부트 시작 시 생성되어야할 기본 데이터를 생성해야하는 경우.
init과 같이 구동과 동시에 필요한 데이터들을 생성할땐 init처럼 사용하면 된다.
@Configuration
public class ExConfig(){
@EventListener(ApplicationReadyEvent.class)
public void init(){
System.out.println("Hello EventListener!! ApplicationReadyEvent");
}
}
https://sslblog.tistory.com/160
Spring : 이벤트 리스너 기본 개념 (@EventListener, @TransactionalEventListener)
Spring : 이벤트 리스너 기본 개념 (@EventListener, @TransactionalEventListener) 이 글에서는 스프링에서 이벤트를 처리하는 어노테이션을 소개합니다. 스프링에서는 이벤트 어노테이션을 통해서 어플리케
sslblog.tistory.com
https://sunghs.tistory.com/139
[Spring] Spring의 @EventListener
Spring의 @EventListener 쓰는 이유? 의존성이 강한 로직들의 레이어를 분리할 수 있습니다. 예를 들어 A 서비스의 a 비즈니스 로직을 실행 할 때 B 서비스의 b 추가 로직을 같이 실행해야 하는 경우 A 서
sunghs.tistory.com
Spring Application Events 처리 및 활용
Spring Application Context Events 1. ContextRefreshedEvent ApplicationContext를 초기화하거나 새로 고칠 때 Spring은 ContextRefreshedEvent를 발생시킵니다. 2. ContextStartedEvent ConfigurableApplicationContext에서 start() 메서드를
eblo.tistory.com
https://jeong-pro.tistory.com/206
스프링 부트 애플리케이션에서 초기화 코드를 넣는 3가지 방법 (by 토비님)
스프링 부트에서 초기화 코드를 넣는 3가지 방법 이 포스트는 토비님의 유튜브 강의를 보고 내용을 정리한 포스트입니다. (출처 : https://www.youtube.com/watch?v=f017PD5BIEc) 위의 영상을 보면서 같이 공
jeong-pro.tistory.com
마지막 참고포스팅이 제일 핵심.
'Spring' 카테고리의 다른 글
lombok 주의사항 _ @Data는 가급적 사용금지. (0) | 2022.11.18 |
---|---|
@RequiredArgsConstructor 롬복 어노테이션으로 자동생성자생성주입 (0) | 2022.11.17 |
@Autowired, @Inject, @Resource 의 차이 (0) | 2022.09.01 |
UriComponentsBuilder (0) | 2022.08.19 |
[spring] annotation 정리 (0) | 2022.07.07 |