작성
·
385
0
package hello.core.lifecycle;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
public class BeanLifeCycleTest {
@Test
public void lifeCycleTest(){
ConfigurableApplicationContext ac = new AnnotationConfigApplicationContext(LifeCycleConfig.class);
System.out.println("1");
NetworkClient client = ac.getBean(NetworkClient.class);
System.out.println("2");
ac.close();
}
@Configuration//
static class LifeCycleConfig {
@Bean
public NetworkClient networkClient() {
NetworkClient networkClient = new NetworkClient();
networkClient.setUrl("http://hello-spring.dev");
return networkClient;
}
}
}
여기서요,
LifeCycleConfig에 @Configuration이 붙으나 안붙으나,
AnnotationConfigApplicationContext에 인자로 주면 똑같은거 아닌가요?
Bean newworkClient 에 따로 스코프 설정도 안했으니까요...
아닌가요?
답변 1
0
안녕하세요. hi_man159님, 공식 서포터즈 David입니다.
아래 글 답변 참고 부탁드립니다:)
https://www.inflearn.com/questions/150061
감사합니다.