spring开发_BeanFactoryPostProcessor_容器后处理器

spring开发_BeanFactoryPostProcessor_容器后处理器,第1张

概述java spring BeanFactoryPostProcessor 容器后处理类

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; 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开发_BeanFactoryPostProcessor_容器后处理器全部内容,希望文章能够帮你解决spring开发_BeanFactoryPostProcessor_容器后处理器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1270041.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存