빈 등록 초기화, 소멸 메서드 지정
public void init() throws Exception {
System.out.println("NetworkClient.init");
connect();
call("초기화 연결 메시지");
}
//빈이 종료될 때 아래 close()호출,실행!
public void close() throws Exception {
System.out.println("NetworkClient.close");
disconnect();
}@Configuration
static class LifeCycleConfig{
@Bean(initMethod = "init",destroyMethod = "close")
public NetworkClient networkClient(){
NetworkClient networkClient = new NetworkClient();
networkClient.setUrl("http://hello-spring.dev");
return networkClient;
}
}Last updated