· 약 4분 AI assisted

Using depends-on

Spring IoC Container (24편)
  1. Spring Framework Overview
  2. Core Technologies
  3. Container Overview
  4. Bean Overview
  5. Dependencies and Configuration in Detail
  6. Using depends-on
  7. Lazy-initialized Beans
  8. Method Injection
  9. Bean Scopes
  10. Customizing the Nature of a Bean
  11. Bean Definition Inheritance
  12. Container Extension Points
  13. Annotation-based Container Configuration
  14. Classpath Scanning and Managed Components
  15. Using JSR-330 Standard Annotations
  16. Basic Concepts: @Bean and @Configuration
  17. Using the @Bean Annotation
  18. Using the @Configuration annotation
  19. Instantiating the Spring Container by Using AnnotationConfigApplicationContext
  20. Autowiring Collaborators
  21. Environment Abstraction
  22. Registering a LoadTimeWeaver
  23. Additional Capabilities of the ApplicationContext
  24. 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 (탐색)

공유

관련 글