Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Bean의 종료 메서드 추론 기능 #8

Open
bong01 opened this issue Mar 8, 2022 · 2 comments
Open

@Bean의 종료 메서드 추론 기능 #8

bong01 opened this issue Mar 8, 2022 · 2 comments

Comments

@bong01
Copy link
Member

bong01 commented Mar 8, 2022

사용자가 편리하게 사용할 수 있도록 컨테이너는 @bean 메서드에서 반환된 객체에 대해 destroyMethod를 추론한다.

현재 이 종료 메서드 추론 기능은 close 혹은 shutdown이라는 이름의 public, no-arg 메서드로 제한되어 있다.
따라서, 객체에 close라는 이름의 메서드를 구현해놓았다면 따로 destoryMethod로 등록하지 않아도 해당 메서드를 스프링이 알아서 등록해 준다.

만약, 추론 기능을 사용하기 싫다면 destroyMethod="" 처럼 빈 공백을 지정하면 된다.

@YoumHyeJi
Copy link

@bean 애너테이션에서 destroyMethod 애트리뷰트를 지정하거나, 빈으로 등록된 클래스 안에 close 혹은 shutdown이라는 이름의 메서드를 만들면 되는 구나!
나중에 실습해볼게!

@ksi05503
Copy link
Contributor

추론기능 모르고 일반메소드에 close 이런거 이름으로 썼다가 destroy method로 등록되버릴뻔했네

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants