spring开发_BeanFactoryPostProcessor_容器后处理器

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; MeatService meatService; DogServiceBean() { 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.MeatService; FishServiceBean MeatService { FishServiceBean(){ System.out.println("鱼肉类被初始化了"); } @Override String whatMeat() { "鱼肉"; } }

com.b510.service.impl; com.b510.service.MeatService; PorkServiceBean MeatService { PorkServiceBean(){ System.out.println("猪肉类被初始化了"); } @Override String whatMeat() { "猪肉"; } }

xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http: ="com.b510.service.impl.FishServiceBean"> ="com.b510.service.impl.PorkServiceBean"> ="com.b510.service.impl.DogServiceBean" p:age="12" p:meatService-ref="meatServiceOfPork" /> ="com.b510.service.impl.CatServiceBean" p:age="3" p:meatService-ref="meatServiceOfFish" /> ="com.b510.app.util.MyBeanFactoryPostProcessor">

2012-3-12 20:28:20 org.springframework.context.support.AbstractApplicationContext prepareRefresh信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@15eb0a9: display name [org.springframework.context.support.ClassPathXmlApplicationContext@15eb0a9]; startup date [Mon Mar 12 20:28:20 CST 2012]; root of context hierarchy2012-3-12 20:28:20 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions信息: Loading XML bean definitions from path resource [beans.xml]2012-3-12 20:28:24 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory信息: Bean factory application context [org.springframework.context.support.ClassPathXmlApplicationContext@15eb0a9]: org.springframework.beans.factory.support.DefaultListableBeanFactory@4a63d8比较一下上面信息********************Spring容器是:org.springframework.beans.factory.support.DefaultListableBeanFactory@4a63d8: defining beans [meatServiceOfFish,meatServiceOfPork,animaleServiceOfDog,animaleServiceOfCat,appBeanPostProcessor]; root of factory hierarchy比较一下下面信息********************2012-3-12 20:28:24 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@4a63d8: defining beans [meatServiceOfFish,appBeanPostProcessor]; root of factory hierarchy鱼肉类被初始化了猪肉类被初始化了狗类被初始化了猫类被初始化了我是狗,我的年龄是:12,我很喜欢吃猪肉我是猫,我的年龄是:3,我很喜欢吃鱼肉

相关文章

这篇文章主要介绍了spring的事务传播属性REQUIRED_NESTED的原...
今天小编给大家分享的是一文解析spring中事务的传播机制,相...
这篇文章主要介绍了SpringCloudAlibaba和SpringCloud有什么区...
本篇文章和大家了解一下SpringCloud整合XXL-Job的几个步骤。...
本篇文章和大家了解一下Spring延迟初始化会遇到什么问题。有...
这篇文章主要介绍了怎么使用Spring提供的不同缓存注解实现缓...