반응형

preDestory

    Java 9 이후 deprecated된 Spring @PostConstruct와 @PreDestory 대안소개

    이 둘은 Bean의 생성 (생성자가 호출 된 후)과 소멸 시점에서 실행할 부분을 정의할때 사용한다. 하지만 @PostConstruct와 @PreDestory 어노테이션은 Java 9에서 Deprecated 되었고 Java 11에서는 제거될 예정이다. 그래서 이와 같은 동작이 필요할 때 사용할 수 있는 대안을 소개한다. InitializingBean, DisposableBean 인터페이스 구현 두 개의 인터페이스를 구현하면서 afterPropertiesSet()과 destroy() 메서드를 재정의하면서 deprecated된 두개의 어노테이션을 대신할 수 있다. 123456789101112131415161718192021@Servicepublic class UserService implements UserS..

반응형