다음 스프링 애플리케이션 컨텍스트와 클래스 A가 주어지면 클래스 A를 실행할 때 어떤 일이 발생합니까? (클래스 경로에)빈이 생성자에 Spring 애플리케이션 컨텍스트를로드하려고하면 어떻게 될까?
applicationContext.xml :
<?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 name="a" class="A"/>
</beans>
A.java :
class A {
private ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
public static void main(String[] args) {
A a = new A();
}
}
http://stackoverflow.com/questions/2923813/how-should-each-class-in-an-application-retrieve-the-spring-application-context에 관련 질문을 게시했습니다. –