Spring默认以单例形式管理bean
让spring管理管理HelloWorld的实例
Spring的配置文件
beans.xml
相当于new了一个类的对象,通过id来取类的对象
HelloWorld类
public class HelloWorld {
public void say(){
System.out.println("Spring");
}
}
加载spring的bean
public class Test {
public static void main(String[] args) {
ApplicationContext ac=new ClassPathXmlApplicationContext("beans.xml");
HelloWorld helloWorld=(HelloWorld)ac.getBean("helloWorld");
helloWorld.say();
}
}