Loading...
Spring Framework Reference Documentation 7.0.2의 Using @PostConstruct and @PreDestroy의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
@PostConstruct and @PreDestroyCommonAnnotationBeanPostProcessor는 @Resource 어노테이션뿐만 아니라 JSR-250 lifecycle 어노테이션인 jakarta.annotation.PostConstruct와
jakarta.annotation.PreDestroy도 인식합니다. Spring 2.5에서 도입된 이러한 어노테이션에 대한 지원은
initialization callbacks 및
destruction callbacks에 설명된 lifecycle 콜백 메커니즘에 대한 대안을 제공합니다.
CommonAnnotationBeanPostProcessor가 Spring ApplicationContext
내에 등록되어 있으면, 이러한 어노테이션 중 하나를 가진 메서드는 해당하는 Spring lifecycle 인터페이스 메서드 또는 명시적으로 선언된 콜백
메서드와 lifecycle 상 동일한 시점에 호출됩니다. 다음 예에서는 cache가 initialization 시에 미리 채워지고
destruction 시에 clear됩니다:
1public class CachingMovieLister { 2 3 @PostConstruct 4 public void populateMovieCache() { 5 // populates the movie cache upon initialization... 6 } 7 8 @PreDestroy 9 public void clearMovieCache() { 10 // clears the movie cache upon destruction... 11 } 12}
1class CachingMovieLister { 2 3 @PostConstruct 4 fun populateMovieCache() { 5 // populates the movie cache upon initialization... 6 } 7 8 @PreDestroy 9 fun clearMovieCache() { 10 // clears the movie cache upon destruction... 11 } 12}
For details about the effects of combining various lifecycle mechanisms, see Combining Lifecycle Mechanisms.
@Resource와 마찬가지로,@PostConstruct및@PreDestroy어노테이션 타입은 JDK 6에서 8까지 표준 Java 라이브러리의 일부였습니다.<br>그러나 전체javax.annotation패키지는 JDK 9에서 core Java 모듈에서 분리되었고, 결국 JDK 11에서 제거되었습니다.<br>Jakarta EE 9부터 이 패키지는 이제jakarta.annotation에 존재합니다. 필요하다면,<br>jakarta.annotation-api아티팩트를 이제 Maven Central을 통해 얻어야 하며,<br>다른 라이브러리와 마찬가지로 애플리케이션의 classpath에 단순히 추가하면 됩니다.
Using @Value
Classpath Scanning and Managed Components