Resolved
Written on
·
199
0
public class BeanLifeCycleTest {
@Test
public void lifeCycleTest() {
ConfigurableApplicationContext ac = new
AnnotationConfigApplicationContext(LifeCycleConfig.class);
NetworkClient client = ac.getBean(NetworkClient.class);
ac.close(); //스프링 컨테이너를 종료, ConfigurableApplicationContext 필요 }
@Configuration
static class LifeCycleConfig {
@Bean
public NetworkClient networkClient() {
NetworkClient networkClient = new NetworkClient();
networkClient.setUrl("http://hello-spring.dev");
return networkClient;
} }
}
의의 테스트 코드를 실행하면 url 이 null 값으로 출력되는것이 당연하다느 부분이 잘 이해 되지 않습니다.
스프링 등록하는 @Configuration 에 이미 setUrl 로 "http://~" 로 setUrl이 이미 설정이 되어 있는데 왜 null값이 나오는것 일까요?
@Bean
public NetworkClient networkClient() {
NetworkClient networkClient = new NetworkClient();
networkClient.setUrl("http://hello-spring.dev");
return networkClient;
}