우리는 Java 기반 Spring 구성을 수행하기 위해 @Configuration
클래스를 사용합니다. 계층 구조를 AnnotationConfigApplicationContext
(s)으로 설정하려고합니다.주석 기반 구성 계층
작동하는 것 같습니다. 자식 컨텍스트 중 하나에서 만든 Bean의 멤버로 부모 컨텍스트의 Bean을 Autowire 할 수 있습니다.
그러나 상위 콘텍스트의 bean을 @Configuration
클래스 파일로 Autowire 처리하는 것이 아니라 매우 편리합니다. 그들은 모두 null입니다. 이 샘플에서
// a sample bean
@Component
public class ChildBeanOne{
@Autowired parentBeanTwo
}
// child context config
@Configuration
public class ChildContextConfig{
@Autowired parentBeanOne
@Bean childBeanOne...
}
// parent context config
@Configuration
public class ParentContextConfig{
@Bean parentBeanOne...
@Bean parentBeanTwo...
}
은, 내가 무엇을 얻고 것은
parentBeanOne
이 설정 파일 (
null
)를 autowire되지 않은 상태에서 제대로 만들어
parentBeanTwo
입니다.
무엇이 누락 되었습니까?
부모/자녀 관계를 어떻게 설정 했습니까? – skaffman
부모 컨텍스트에서 AnnotationConfigApplicationContext를 Bean으로 선언하면 ChildContexts에 autowiring이 작동한다는 것을 발견했습니다. 그러나 "순환 참조"를 받기 시작합니다. 관련 예외 ... 순환 참조를 식별 할 수 없습니다. – Rafael
@configurable config 클래스를 등록하기 전에 setParent (ctx)를 사용하여 관계를 설정합니다. – Rafael