강의

멘토링

커뮤니티

Inflearn Community Q&A

banana2051385's profile image
banana2051385

asked

Spring Core Principles - Basic Edition

Getting Started with Component Scan and Automatic Dependency Injection

ComponentScan 문의드립니다.

Resolved

Written on

·

254

1

안녕하세요

다름이 아니고 excludeFilters에서 class제외할때 Configuration.class 를 제외하는데요

@Configuration
@ComponentScan(
basePackages = "hello.core.member",
excludeFilters = @Filter(type= FilterType.ANNOTATION, classes = Configuration.class)
)

Configuration을 클래스로 볼수 있는건가요?

생각으로는 AppConfig.class로 적어야 할것 같아서요.

@Configuration을 따라가면 @Component가 있어서 @Configuration을 exclude시켜야 하는건 알겠지만 AnnotationConfigApplicationContext를 new할때도 AppConfig.class를 넣어줬던걸로 기억을 해서요.

답변 부탁드리겠습니다. 늘 감사합니다!

oopspring

Answer 2

1

ALAN KIM님의 프로필 이미지
ALAN KIM
Questioner

항상 빠른 답변 감사합니다!!

화이팅하겠습니다!

1

yh님의 프로필 이미지
yh
Instructor

안녕하세요. ALAN KIM님

FilterType.ANNOTATION이기 때문에 애노테이션을 적어주어야 합니다. 따라서 Configuration.class인 애노테이션을 적어주는 것이 맞습니다.

Q: AnnotationConfigApplicationContext를 new할때도 AppConfig.class 넣어줬던 걸로 기억을 해서요

-> new AnnotationConfigApplicationContext(AppConfig.class)를 하면 AppConfig는 무조껀! 스프링 빈으로 자동 등록됩니다. 생각해보면 AppConfig가 일단 스프링빈으로 등록이 되어야 AppConfig위에 있는 @ComponentScan도 동작하니까요^^

도움이 되셨길 바래요.

banana2051385's profile image
banana2051385

asked

Ask a question