2012-03-27 2 views
0
class AbstractBeanFactory 

    public void setParentBeanFactory(BeanFactory parentBeanFactory) { 
    if (this.parentBeanFactory != null && this.parentBeanFactory != parentBeanFactory) { 
     throw new IllegalStateException("Already associated with parent BeanFactory: " + this.parentBeanFactory); 
    } 
    this.parentBeanFactory = parentBeanFactory; 
} 

나의 요구 사항은 다른 하나를 AppContext로 참조하는 AppContext 체인을 부모로 참조하는 것입니다. parentage도 AppContext의 해당 DefaultListableBeanFactory까지 확장됩니다. 즉, Context의 DefaultListableBeanFactory은 부모 Context의 DefaultListableBeanFactory을 부모로 참조합니다. 체인의 모든 컨텍스트에있는 Bean을 맨 아래의 AppContext에서 검색 할 수 있도록이 작업이 수행됩니다.Java : spring : AbstractBeanFactory가 부모 BeanFactory를 변경할 수없는 이유는 무엇입니까?

이 체인은 동적이며, 새로운 AppContext가 맨 위에 추가되며 모든 AppContext는 중간에서 삭제 될 수 있습니다.

하지만 중간에서 AppContext를 삭제하고 DefaultListableBeanFactory 부모 관계를 변경하려고하면 위의 예외가 발생합니다.

런타임시 공장 관계를 어떻게 바꿀 수 있습니까?

감사, 감사 비멀

답변

1

나는 부모 콩 공장은 마지막으로 설계 생각이 내 의견에 합리적인 디자인 선택이 될 것입니다. 그것을 다른 것으로 바꾸면 많은 불일치와 예측할 수없는 행동으로 이어질 것입니다.

상위 컨텍스트에서 주입 된 빈에 종속성이있는 경우 상위 컨텍스트를 바꾸면 어떻게됩니까? 이 종속성이 재 주입되어야 하는가? 그렇다면 프로토 타입 bean은 어떻게 추적 할 것인가? 그렇지 않다면, 상위 컨텍스트에서 빈의 범위가 변경되면 어떻게 될까요?

스프링은 컨텍스트의 부분적 새로 고침을 허용하지 않으며 그러한 작업을 시도 할 때와 같은 상위 컨텍스트 사운드를 바꾸지 않습니다.

아마 당신이 당신의 문제를 좀 더 자세히 설명하고, 몇 가지 예를 들어 보았을 때, 당신의 질문에 건설적인 제안으로 대답하는 것이 가능할 수도 있습니다.

+0

다른 질문에서 문제를 설명했습니다. http://stackoverflow.com/questions/9885350/java-spring-how-to-transfer-beans-from-one-classpathxmlapplicationcontext-to-a – weima

관련 문제