rhakdnj / kopring

0 stars 0 forks source link

@PostConstruct & @PreDestroy #6

Open rhakdnj opened 8 months ago

rhakdnj commented 8 months ago

PostConstruct

jakarta.annotation.PostConstruct Spring IoC 컨테이너에서 의존성이 연결된 직 후에 @PostConsturct에 정의된 메서드를 한 번 Call 한다.

@Component
class PostConstructBean {
  @PostConstruct
  fun init() {
    println("Called PostConstruct")
  }
}

@Configuration
@ComponentScan
class PostConstructSample

fun main() {
  val context = AnnotationConfigApplicationContext(PostConstructSample::class.java)

  // No call @PostConstruct !
  val bean = PostConstructBean()
}