1. Lazy-initialized Beans
구분 | 설명 | 비고 |
기본 동작 | ApplicationContext는 초기화 시 모든 싱글톤 빈을 즉시 생성 |
설정 오류를 초기화 시점에 조기 발견 가능
|
지연 초기화 (Lazy) | 빈의 생성 시점을 첫 요청 시점으로 지연 |
자원 절약, 시작 시간 단축
|
설정
예시) XML
더보기
<bean id="lazy" class="com.something.ExpensiveToCreateBean" lazy-init="true"/>
<bean name="not.lazy" class="com.something.AnotherBean"/>
- <bean/> 요소의 lazy-init 속성으로 제어됩니다.
예시) XML (컨테이너 수준)
더보기
<beans default-lazy-init="true">
<!-- no beans will be pre-instantiated... -->
</beans>
- default-lazy-init 속성을 사용하여 컨테이너 수준에서 지연 초기화를 제어할 수 있습니다.
예외 사항
Lazy 된 빈이 Non-Lazy 빈의 의존성인 경우
- 해당 싱글톤 빈의 종속성을 만족시키기 위해, ApplicationContext는 지연 초기화 된 빈을 즉시 생성합니다.
출처
'Spring > Spring' 카테고리의 다른 글
[Spring][Integration] 1. Task Execution: @Async (0) | 2023.10.16 |
---|---|
[Spring][Core] 2-8. Bean: Customizing the Nature of a Bean (0) | 2023.10.14 |
[Spring][Core] 2-6. Bean: Autowiring Collaborators (0) | 2023.10.14 |
[Spring][Core] 2-5. Bean: Dependency Injection (0) | 2023.10.14 |
[Spring][Core] 2-4. Bean: Scopes (0) | 2023.10.14 |