You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
역시 @PostConstruct, @PreDestroy 애너테이션을 사용하는게 코드도 깔끔하고, 스프링에 종속되지 않아서 좋은 거 같아~
외부 라이브러리를 초기화, 종료할 땐 @bean의 initMethod, destroyMethod 애트리뷰트를 설정하면 된다는 건 처음 알았다!!
빈 라이프 사이클에 대해 공부하던 중,
빈 라이프 사이클 콜백 방법에 대해 각각의 장점과 단점을 정리해보았습니다.
스프링은 크게 3가지 방법으로 빈 라이프 사이클 콜백을 지원합니다.
초기화, 소멸 인터페이스 단점
참고: 인터페이스를 사용하는 초기화, 종료 방법은 스프링 초창기에 나온 방법들이고, 지금은 다음의 더
나은 방법들이 있어서 거의 사용하지 않는다.
빈 등록 초기화, 소멸 메서드 지정
애노테이션 @PostConstruct, @PreDestroy
유일한 단점은 외부 라이브러리에는 적용하지 못한다는 것이다. 외부 라이브러리를 초기화, 종료 해야 하면
@bean의 기능을 사용하자.
정리
@PostConstruct, @PreDestroy 애노테이션을 사용하자
코드를 고칠 수 없는 외부 라이브러리를 초기화, 종료해야 하면 @bean 의 initMethod , destroyMethod
를 사용하자.
The text was updated successfully, but these errors were encountered: