티스토리 뷰
Spring Boot에서 Bean은 총 2단계로 등록이 된다.
그 내용을 살펴보기 전에 먼저, @SpringBootApplication을 확인해보면 아래와 같은 구조로 되어 있는 것을 볼 수 있다.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
...
}
여기서 중요한 Annotation이 @SpringBootConfiguration, @ComponentScan, @EndableAutoConfiguration 이다.
각각에 대해서 살펴보자면
1. @SpringBootConfiguration 은 일반적인 @Configuration 으로 일반 설정 파일이다.
2. @ComponentScan 은 해당 Annotation을 가지고 있는 하위 클래스의 모든 클래스를 대상으로 @Component Annotation을 가지고 있는지 Scan하고 Bean으로 등록하는 역할을 한다.
-> 서론에 언급한 2단계 Bean등록 중 1단계
- @Component에 해당하는 Annotation
: @Component @Repository @Service @Comtroller @RestController @Configuration
3. @EnableAutoConfiguration 은 Spring Boot의 Meta 파일안에 미리 정의되어 있는 Configuration 파일을 Bean으로 등록하는 역할을 한다. (spring-boot-autoconfigure 프로젝트 아래 META-INF의 spring.factories File)
-> 서론에 언급한 2단계 Bean등록 중 2단계 (이 값이 1단계의 값을 Overwrite)

spring.factories 파일 안의 autoConfiguration을 모두 읽어 들이며, 각각 특정 조건에 따라 (@ConditionalOnXXX) 혹은 순서에 따라 (@AutoConfigureAfter @Order ...) Bean등록이 이루어진다.
@ 출처
'프로그래밍 > Spring Boot' 카테고리의 다른 글
| [Spring Boot] 6. profile 설정 (0) | 2021.03.08 |
|---|---|
| [Spring Boot] 5. 외부 설정 (0) | 2021.03.07 |
| [Spring Boot] 4. Spring Boot 특징 - 기본편 (0) | 2021.03.02 |
| [Spring Boot] 3. 자동 설정 구현(2) (0) | 2021.03.02 |
| [Spring Boot] 2. 자동 설정 구현 (0) | 2021.03.01 |