href="http://www.cnblogs.com/hongten/gallery/image/112611.HTML">http://www.cnblogs.com/hongten/gallery/image/112611.HTML
com.b510.app.test; org.springframework.context.ApplicationContext; org.springframework.context.support.ClasspathXmlApplicationContext; com.b510.service.AnimalService; SpringTest { main(String[] args) { ApplicationContext act = ClasspathXmlApplicationContext("beans.xml"); AnimalService animalServiceOfDog = (AnimalService) act .getBean("animaleServiceOfDog"); animalServiceOfDog.getInfo(); AnimalService animalServiceOfCat = (AnimalService) act .getBean("animaleServiceOfCat"); animalServiceOfCat.getInfo(); } }
com.b510.app.util; org.springframework.beans.BeansException; org.springframework.beans.factory.config.beanfactoryPostProcessor; org.springframework.beans.factory.config.Configurablelistablebeanfactory; MybeanfactoryPostProcessor beanfactoryPostProcessor { postProcessbeanfactory( Configurablelistablebeanfactory beanfactory) BeansException { System.out.println("比较一下上面信息********************"); System.out.println("spring容器是:" + beanfactory); System.out.println("比较一下下面信息********************"); }}
com.b510.service; AnimalService { getInfo(); }
com.b510.service; meatService { String whatmeat(); }
com.b510.service.impl; com.b510.service.AnimalService; com.b510.service.meatService; CatServiceBean AnimalService { age; meatService meatService; CatServiceBean(){ System.out.println("猫类被初始化了"); } getAge() { age; } @OverrIDe getInfo() { System.out.println("我是猫,我的年龄是:"+age+",我很喜欢吃"+meatService.whatmeat()); } meatService getmeatService() { meatService; } setAge( age) { .age = age; } setmeatService(meatService meatService) { .meatService = meatService; } }
com.b510.service.impl; com.b510.service.AnimalService; com.b510.service.meatService; DogServiceBean AnimalService { age;