Packagessh.spring;Importjava.io.IOException;Importorg.springframework.beans.factory.BeanFactory;Importorg.springframework.beans.factory.xml.XmlBeanFactory;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext;ImportOrg.springframework.core.io.ClassPathResource;ImportOrg.springframework.core.io.FileSystemResource;ImportOrg.springframework.core.io.Resource; Public classTest {@org. junit.test Public voidtest1 () {ApplicationContext AC=NewClasspathxmlapplicationcontext ("Ssh/spring/applicationcontext.xml"); Person P1= (person) ac.getbean (' person '); System.out.println ("Test1" +p1); } @org. junit.test Public voidtest2 () {ApplicationContext AC=NewClasspathxmlapplicationcontext ("Applicationcontext.xml", This. GetClass ()); Person P1= (person) ac.getbean (' person '); System.out.println ("Test2" +p1); } @org. junit.test Public voidtest3 () {Resource Resource=NewClasspathresource ("Ssh/spring/applicationcontext.xml"); Beanfactory beanfactory=Newxmlbeanfactory (Resource); Person P1= (person) beanfactory.getbean (' person '); System.out.println ("Test3" +p1); } @org. junit.test Public voidTest4 ()throwsioexception{Resource Resource=NewClasspathresource ("Applicationcontext.xml", This. GetClass ()); Beanfactory beanfactory=Newxmlbeanfactory (Resource); Person P1= (person) beanfactory.getbean (' person '); System.out.println ("Test4" +p1); } @org. junit.test Public voidTest5 () {Resource Resource=NewFilesystemresource ("E:/java/study/webroot/web-inf/classes/ssh/spring/applicationcontext.xml"); Beanfactory beanfactory=Newxmlbeanfactory (Resource); Person P1= (person) beanfactory.getbean (' person '); System.out.println ("Test5" +p1); }}
Several methods for initializing spring containers