Skip to content

Commit

Permalink
애노테이션 @PostConstruct, @PreDestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
kiteB committed Aug 30, 2021
1 parent 5b65842 commit a233f18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions 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;
Expand All @@ -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();
Expand Down

0 comments on commit a233f18

Please sign in to comment.