我的世界api是什么coooa beans是什么

我的世界cocoa beans长什么样子_百度知道
我的世界cocoa beans长什么样子
可可豆一般在热带雨林中,像树上的灯泡,长在书干上
其他类似问题
cocoa的相关知识
按默认排序
其他1条回答
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁2645人阅读
首先看代码实例:
SimpleBean.java
package&ch5.BeanAimport&org.springframework.beans.BeansEimport&org.springframework.beans.factory.BeanFimport&org.springframework.beans.factory.BeanFactoryAimport&org.springframework.beans.factory.BeanNameAimport&org.springframework.beans.factory.DisposableBimport&org.springframework.beans.factory.InitializingBimport&org.springframework.beans.factory.config.ConfigurableListableBeanFimport&ch5.destroy.ShutDownHpublic&class&SimpleBean&implements&InitializingBean,DisposableBean,BeanNameAware,BeanFactoryAware,Runnable&...{&&private&ConfigurableListableBeanFactory&configurableListableBeanF&&public&void&setBeanName(String&beanName)&...{&&&&&&&&System.out.println(&this&is&info&from&BeanNameAware&and&beanName&is:&+beanName);&&&&&&&&&&&&}&&&&public&void&setBeanFactory(BeanFactory&factory)&throws&BeansException&...{&&&&&&&&//自动注册成线程&&&&&&&&if(factory&instanceof&ConfigurableListableBeanFactory)...{&&&&&&&&&&&&System.out.println(&this&is&info&from&BeanNameAware&and&beanName&);&&&&&&&&&&&&this.configurableListableBeanFactory=(ConfigurableListableBeanFactory)&&&&&&&&&&&&&&Runtime.getRuntime().addShutdownHook(new&Thread(this));&&&&&&&&}&&&&&&&&&&&&}&&&&public&void&afterPropertiesSet()&throws&Exception&...{&&&&&&&&System.out.println(&this&is&info&from&afterpropertiesSet&from&SimpleBean&);&&&&}&&&&public&void&run()&...{&&&&&&&&//线程调用destroySingletons&&&&&&&&configurableListableBeanFactory.destroySingletons();&&&&&&&&&&&&}&&private&String&&&private&String&&&private&String&&&public&void&destroyMethod()...{&&&&&&System.out.println(&this&is&info&from&customer&destroy&method&);&&}&&public&void&destroy()...{&&&&&&System.out.println(&this&is&info&from&destroy&method&);&&}public&String&getAge()&...{&&&&return&}public&void&setAge(String&age)&...{&&&&this.age&=&}public&String&getName()&...{&&&&return&}public&void&setName(String&name)&...{&&&&this.name&=&}public&String&getSex()&...{&&&&return&}public&void&setSex(String&sex)&...{&&&&this.sex&=&}}
&配置文件:
&?xml&version=&1.0&&encoding=&UTF-8&?&&beans&&&&xmlns=&http://www.springframework.org/schema/beans&&&&&xmlns:xsi=&http://www.w3.org/2001/XMLSchema-instance&&&&&xsi:schemaLocation=&http://www.springframework.org/schema/beans&http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&&&bean&id=&SimpleBean&&class=&ch5.destroy.SimpleBean&&destroy-method=&destroyMethod&&&property&name=&name&&&&&&&value&gaoxiang&/value&&&&/property&&property&name=&sex&&&&&&value&male&/value&&/property&&property&name=&age&&&&&&&value&<span style="COLOR: #&/value&&&&/property&&/bean&&/beans&
测试代码:
package&ch5.BeanAimport&java.io.Fimport&org.springframework.beans.factory.BeanFimport&org.springframework.beans.factory.config.ConfigurableListableBeanFimport&org.springframework.beans.factory.support.BeanDefinitionRimport&org.springframework.beans.factory.xml.XmlBeanFimport&org.springframework.core.io.FileSystemRpublic&class&TestSpring...{&&public&static&void&main(String&args[])&&throws&Exception...{&&&&&&//获取bean&factory&&&&&&ConfigurableListableBeanFactory&factory=(ConfigurableListableBeanFactory)getBeanFactory();&&//使用子beanFactory&&&&&&&&&&&factory.preInstantiateSingletons();&&&&&&SimpleBean&bean1=(SimpleBean)factory.getBean(&SimpleBean&);&&&&&&&&}&&public&static&BeanFactory&getBeanFactory()...{&&&&&&//获取bean&factory&&&&&&String&realpath=&&;&&&&&&&&&&&&//加载配置项&&&&&&realpath=System.getProperty(&user.dir&)+File.separator+&src&+File.separator+&ch5/destroy&+File.separator+&applicationContext.xml&;&&&&&&&&&&&&&ConfigurableListableBeanFactory&&factory=new&XmlBeanFactory(new&FileSystemResource(realpath));&&&&&&&&&&&&return&&&}}
一点说明:
实现BeanNameAware接口需要实现setBeanName()方法,这个方法只是简单的返回我们当前的beanName
实现BeanFactoryAware,我们
&public&void&run()&...{&&&&//线程调用destroySingletons&&&&configurableListableBeanFactory.destroySingletons();&&&&&&&&}
可以调用到获得Bean的工厂,需要实现setBeanFactory方法
看测试程序的这段代码:
&ConfigurableListableBeanFactory&factory=(ConfigurableListableBeanFactory)getBeanFactory();&&&&factory.preInstantiateSingletons();SimpleBean&bean1=(SimpleBean)factory.getBean(&SimpleBean&);
我们对ConfigurableListableBeanFactory&.preInstantiateSingletons();进行了调用,默认情况下,只有用到singleton Bean的时候,spring才会使用懒汉式子进行初始化,这对SimpleBean可是个大麻烦,因为它需要实例化后才能注册成为shutdown hook,调用preInstantiateSingletons()可让spring立即处理其全部的bean定义并创建实例,测试代码中并没有调用destroySingleton(),因为simpleBean已经在run方法中进行调用了。如下:
&public void run() {&&& &//线程调用destroySingletons&&configurableListableBeanFactory.destroySingletons();&}
运行结果:
this is info from BeanNameAware and beanName is:SimpleBeanthis is info from BeanNameAware and beanNamethis is info from afterpropertiesSet from SimpleBeanthis is info from destroy methodthis is info from customer destroy method
也可以看到,执行顺序是BeanNameAware,BeanFactoryAware,afterPropertiesSet,customer-Init,disposeable,customer-destroy
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1371173次
积分:21603
积分:21603
排名:第111名
原创:769篇
转载:165篇
评论:439条
(1)(2)(2)(9)(23)(27)(13)(95)(87)(37)(55)(50)(88)(74)(64)(83)(106)(43)(34)(41)我的世界cocoa beans在哪_百度知道
我的世界cocoa beans在哪
提问者采纳
丛林物群系丛林木随机~高兴楼主解答 望采纳~~
其他类似问题
cocoa的相关知识
按默认排序
其他1条回答
丛林物群系丛林木随机
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁我的世界中coooa beand是什么_百度知道
我的世界中coooa beand是什么
我有更好的答案
按默认排序
是可可豆,可以用来将羊毛染成棕色,或和两个小麦合成八个曲奇,个人认为还是很有用的。
其他类似问题
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 我的世界mod是什么 的文章

 

随机推荐