오류 로그
AnnotationConfigApplicationContext@4dbb42b7 has not been refreshed yet
뚜껑뚜
2022. 1. 1. 17:16
에러 발생 상황
public class ComponentFilterAppConfigTest {
@Test
void filterScan() {
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
BeanA beanA = ac.getBean("beanA", BeanA.class);
assertThat(beanA).isNotNull();
}
@Configuration
@ComponentScan(
includeFilters = @Filter(type = FilterType.ANNOTATION, classes = MyIncludeComponent.class),
excludeFilters = @Filter(type = FilterType.ANNOTATION, classes = MyExcludeComponent.class)
)
static class ComponentFilterAppConfig {
}
}
위의 코드 강의 실습 중 테스트를 실행했더니 아래와 같은 오류가 발생했다.
문제 파악
자세히 보니 AnnotationConfigApplicationContext(); 괄호에 파라미터로 클래스를 지정 안 해줬다.
문제 해결
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ComponentFilterAppConfig.class);
클래스를 지정해줬더니 잘 실행된다.