spring学习笔记(2)

spring对单态模式和工厂模式的实现

package com.szlongtu.xz;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

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




	
	
郁闷了照着书写的,调试报错,不知错哪儿,但是工厂模式和单态模式应该是懂了。

你可能感兴趣的:(spring)