3
나는 응용 프로그램 컨텍스트의 계층 구조를 가지고 있습니다. 상위 컨텍스트에 정의 된 bean은 하위에 정의 된 bean에 따라 다 (니다.스프링 : 중첩 된 응용 프로그램 컨텍스트
는 "A"빈을 정의하는 XML 파일은 다음과 같습니다public class X {
public static class A {
public B b;
public void setB(B b) { this.b = b; }
}
public static class B { }
public static void main(String[] args) {
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext(
"/a.xml");
go1(parent);
}
public static void go1(ClassPathXmlApplicationContext parent) {
GenericApplicationContext child = new GenericApplicationContext(parent);
child.getBeanFactory().registerSingleton("b", new B());
A a = (A) child.getBean("a");
Assert.assertNotNull(a.b);
}
}
: 나는 경우
가<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="a" class="X$A" autowire="byName" lazy-init="true"/>
</beans>
문제는 B가 A를 주사로 주입되지 않은 것을
에만 발생합니다 여기가 보이는 방법 "b"싱글 톤을 부모와 등록하십시오 - 이것은 내 프로그램에서 옵션이 아닙니다.
아이디어가 있으십니까?