题解代码:
package step2;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import step2.HelloWorld;
public class MainApp {
public static void fun() {
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());
}
}