The document discusses @Component, @Configuration, and @Bean annotations in Spring.
@Component scans packages to automatically detect classes to register as beans. @Configuration allows declaring and configuring beans directly within classes. @Bean defines methods that create and return beans.
The component scan process involves parsing the configuration, scanning classes based on include/exclude filters, registering bean definitions, and finishing bean initialization. Debugging shows how classes are parsed and beans registered.
Dependency injection types are compared, with constructor injection being most reliable and testable due to immutability and dependency detection. Circular dependencies can cause stack overflows at runtime.
9. Component Scan Process
1. Configuration
2. ComponentScan
3. Class
4.
5. &
- ConfigurationClassParser Configuration
10. Component Scan Process
1. Configuration
2. ComponentScan
3. Class
4.
5. &
- ComponentScanAnnotationParser가 컴포넌트 후보를 모두 찾고,
스캔하기 위하여 해당 설정을 파싱하여 가져옴
- basePackages, basePackesClasses, excludeFilters, includeFilters,
lazyInit, nameGenerator, resourcePattern, scopedProxy 등 컴포넌
트들을 스캔하기 위한 설정
11. Component Scan Process
1. Configuration
2. ComponentScan
3. Class
4.
5. &
- basePackage
- ( *.class ) Resource
29. Constructor Injection
Reliability
Field Injection
Setter Injection
More reliable because of immutable variables
Less reliable
https://medium.com/engineering-zemoso/when-not-to-autowire-in-spring-spring-boot-93e6a01cb793
Less reliable
의존성 주입이 필요한 필드를 final 로 선언가능