Using depends-on
Spring IoC Container (24편)
- Spring Framework Overview
- Core Technologies
- Container Overview
- Bean Overview
- Dependencies and Configuration in Detail
- Using depends-on
- Lazy-initialized Beans
- Method Injection
- Bean Scopes
- Customizing the Nature of a Bean
- Bean Definition Inheritance
- Container Extension Points
- Annotation-based Container Configuration
- Classpath Scanning and Managed Components
- Using JSR-330 Standard Annotations
- Basic Concepts: @Bean and @Configuration
- Using the @Bean Annotation
- Using the @Configuration annotation
- Instantiating the Spring Container by Using AnnotationConfigApplicationContext
- Autowiring Collaborators
- Environment Abstraction
- Registering a LoadTimeWeaver
- Additional Capabilities of the ApplicationContext
- The BeanFactory API
원문: Using depends-on
전문 번역
Using depends-on (depends-on 사용하기)
만약 어떤 빈이 다른 빈의 의존성(dependency)이라면, 이는 일반적으로 한 빈이 다른 빈의 프로퍼티로 설정된다는 것을 의미합니다. 전형적으로 이는 XML 기반 메타데이터에서 <ref/> 요소를 사용하거나 autowiring을 통해 달성할 수 있습니다.
그러나 때때로 빈 간의 의존성은 덜 직접적일 수 있습니다. 예를 들어 클래스의 정적 초기화자(static initializer)가 트리거되어야 하는 경우를 들 수 있는데, 데이터베이스 드라이버 등록이 그러한 경우입니다. depends-on 속성 또는 @DependsOn 어노테이션은 이 요소를 사용하는 빈이 초기화되기 전에 하나 이상의 빈을 명시적으로 먼저 초기화하도록 강제할 수 있습니다. 다음 예시는 depends-on 속성을 사용하여 단일 빈에 대한 의존성을 표현합니다:
<bean id="beanOne" class="ExampleBean" depends-on="manager"/><bean id="manager" class="ManagerBean" />여러 빈에 대한 의존성을 표현하려면, depends-on 속성의 값으로 빈 이름 목록을 제공하면 됩니다 (쉼표, 공백, 세미콜론이 유효한 구분자입니다):
<bean id="beanOne" class="ExampleBean" depends-on="manager,accountDao"> <property name="manager" ref="manager" /></bean>
<bean id="manager" class="ManagerBean" /><bean id="accountDao" class="x.y.jdbc.JdbcAccountDao" />Note (참고)
depends-on 속성은 초기화 시점(initialization-time) 의존성과 싱글톤(singleton) 빈의 경우에만 해당되는 대응하는 소멸 시점(destruction-time) 의존성을 모두 지정할 수 있습니다. 특정 빈과 depends-on 관계를 정의한 의존 빈들(dependent beans)은 해당 빈 자체가 소멸되기 전에 먼저 소멸됩니다. 따라서 depends-on은 종료(shutdown) 순서도 제어할 수 있습니다.
Navigation (탐색)
- Prev (이전): Dependencies and Configuration in Detail (의존성과 구성 상세)
- Next (다음): Lazy-initialized Beans (지연 초기화 빈)