第2关:Spring IOC 容器

题解代码:

package step2;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import step2.HelloWorld;

public class MainApp {
	public static void fun() {
		/********** Begin **********/
		ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext2.xml");
		boolean s = app.containsBean("Student");
		System.out.println(s);
		boolean h = app.containsBean("helloworld");
		System.out.println(h);
		HelloWorld helloworld1 = (HelloWorld)app.getBean("helloworld");
		System.out.println(helloworld1.toString());

		HelloWorld helloworld2 = app.getBean("helloworld",HelloWorld.class);
		System.out.println(helloworld2.toString());

		Object helloworld3 = app.getBean("helloworld");
		System.out.println(helloworld3.toString());

		/********** End **********/
	}
}

发布了53 篇原创文章 · 获赞 16 · 访问量 9248

猜你喜欢

转载自blog.csdn.net/Zheng_lan/article/details/105713503