인프런 커뮤니티 질문&답변
BeanLifeCycleTest 오류
작성
·
301
0
[질문 내용]
여기에 질문 내용을 남겨주세요.
안녕하세요 존경하는 김영한 개발자님
강의를 듣다가 개발자님과 동일하게 코드를 작성했는데
에러가 발생해서 질문 남깁니다.
NetworkClient 코드는 다음과 같고,
package hello.core.lifecycle;
public class NetworkClient {
public String url;
public NetworkClient() {
System.out.println("생성자 호출, url = " + url);
connect();
call("초기화 연결 메시지");
}
public void setUrl(String url) {
this.url = url;
}
//서비스 시작시 호출
public void connect() {
System.out.println("connect: " + url);
}
public void call(String message) {
System.out.println("call: " + url + " message = " + message);
}
//서비스 종료시 호출
public void disconnect() {
System.out.println("close: " + url);
}
}
test 코드는 다음과 같습니다.
package hello.core.lifecycle;
import org.junit.jupiter.api.Test;
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);
NetworkClient client = ac.getBean(NetworkClient.class);
ac.close();
}
@Configuration
static class LifeCycleConfig {
@Bean
public NetworkClient networkClient() {
NetworkClient networkClient = new NetworkClient();
networkClient.setUrl("http://hello-spring.dev");
return networkClient;
}
}
}
저 생성자에서 ac.getBean 하는 부분에서 빨간색으로 줄 그어지면서 cannot access hello.core.lifecyle.NetworkClient라고 뜨는데 혹시 어디가 잘못된것일까요... 코드를 잘못쳤나 싶어 두번을 다시작성했는데도 동일한 오류가 발생합니다.
항상 고퀄 강의 잘 보고 있습니다. 감사합니다.
퀴즈
The main reason for separating object creation and initialization in the Spring Bean lifecycle is to allow for dependency injection and other setup logic to be applied after the object has been fully constructed by the constructor.
Memory allocation speed improvement
Resolving the Dependency Injection Completion Point Issue
Constructor Overloading Support
Improve Garbage Collection Efficiency
답변 1
0
안녕하세요. qzxy812님
전체 프로젝트를 압축해서 구글 드라이브로 공유해서 링크를 남겨주세요.
구글 드라이브 업로드 방법은 다음을 참고해주세요.
https://bit.ly/3fX6ygx
주의: 업로드시 권한 문제 꼭 확인해주세요
추가로 다음 내용도 코멘트 부탁드립니다.
1. 실행 방법을 알려주세요.
2. 어떻게 문제를 확인할 수 있는지 자세한 설명을 남겨주세요.
감사합니다






이 문제 해결됐나요?? 저도 같은 문제를 겪고있습니다..