spring开发_BeanFactoryPostProcessor_容器后处理器
发布时间:2020-12-15 01:52:33 所属栏目:大数据 来源:网络整理
导读:com.b510.app.test; org.springframework.context.ApplicationContext; org.springframework.context.support.ClassPathXmlApplicationContext; com.b510.service.AnimalService; SpringTest { main(String[] args) { ApplicationContext act = ClassPathXml
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() { "猪肉"; } }
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,我很喜欢吃鱼肉
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |