From a233f185787b260e9f90829945725193d91f973b Mon Sep 17 00:00:00 2001 From: kiteB Date: Tue, 31 Aug 2021 01:12:38 +0900 Subject: [PATCH] =?UTF-8?q?=EC=95=A0=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98?= =?UTF-8?q?=20@PostConstruct,=20@PreDestroy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/hello/core/lifecycle/BeanLifeCycleTest.java | 4 ++-- core/src/test/java/hello/core/lifecycle/NetworkClient.java | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/hello/core/lifecycle/BeanLifeCycleTest.java b/core/src/test/java/hello/core/lifecycle/BeanLifeCycleTest.java index ba79cdd..8806486 100644 --- a/core/src/test/java/hello/core/lifecycle/BeanLifeCycleTest.java +++ b/core/src/test/java/hello/core/lifecycle/BeanLifeCycleTest.java @@ -17,8 +17,8 @@ public void lifeCycleTest() { @Configuration static class LifeCycleConfig { - - @Bean(initMethod = "init", destroyMethod = "close") + + @Bean public NetworkClient networkClient() { NetworkClient networkClient = new NetworkClient(); networkClient.setUrl("http://hello-spring.dev"); diff --git a/core/src/test/java/hello/core/lifecycle/NetworkClient.java b/core/src/test/java/hello/core/lifecycle/NetworkClient.java index b100e03..253090f 100644 --- a/core/src/test/java/hello/core/lifecycle/NetworkClient.java +++ b/core/src/test/java/hello/core/lifecycle/NetworkClient.java @@ -1,5 +1,8 @@ package hello.core.lifecycle; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + public class NetworkClient { private String url; @@ -26,12 +29,14 @@ public void disconnect() { System.out.println("close: " + url); } + @PostConstruct public void init() { System.out.println("NetworkClient.init"); connect(); call("초기화 연결 메시지"); } + @PreDestroy public void close() { System.out.println("NetworkClient.close"); disconnect();