spring 공장 모델 구현

1034 단어 spring
bean.xml

<!-- beans Spring        -->
<beans>
    <bean id="chinese" class="lee.Chinese" />
    <bean id="american" class="lee.American" />
</beans>

주 프로그램 (SpringTest)

public static void main(String[] args) {
   //   Spring  
   ApplicationContext ctx =  new FileSystemXmlApplicationContext("bean.xml");   
   Person  p= null;   
   p=(person)ctx.getBean("chinese");   
   System.out.println(p.sayHello("wawa"));   
   System.out.println(p.sayCoogbye("wawa"));   
   p=(Person)ctx.getBean("american");   
   System.out.println(p.sayHello("wawa"));   
   System.out.println(p.sayGoodBye("wawa"));   
}

위 에서 알 수 있 듯 이 Application Context 는 Factory Person 류 와 같 기 때문에 Spring 은 인터페이스 와 인 터 페 이 스 를 실현 하 는 류 만 있 으 면 공장 이 생 겨 공장 류 의 실현 이 필요 없다.

좋은 웹페이지 즐겨찾기