本文实例讲述了春天实战之豆销毁之前的行为操作。分享给大家供大家参考,具体如下:
& lt; & # 63; xml version=" 1.0 " encoding=" GBK " & # 63;比; & lt;豆类xmlns: xsi=" http://www.w3.org/2001/XMLSchema-instance " xmlns=" http://www.springframework.org/schema/beans " xsi: schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd”比; & lt; bean id=皊teelAxe”类=皁rg.crazyit.app.service.impl.SteelAxe”/比; & lt; !——配置中国的Bean,使用销毁方法=肮乇铡? 指定该Bean实例被销毁之前,春天会自动执行指定该Bean的近方法——比; & lt; bean id=爸泄健崩?皁rg.crazyit.app.service.impl.Chinese” 销毁方法=肮乇铡北? & lt;属性名=案眗ef=" steelAxe "/比; & lt;/bean> & lt;/beans>
1斧
包org.crazyit.app.service; 公共接口斧 { 公共字符串切(); } >之前2人
包org.crazyit.app.service; 公共接口人 { 公共空间useAxe (); } >之前中国
1
包org.crazyit.app.service.impl; 进口org.springframework.beans.factory.DisposableBean; 进口org.crazyit.app.service。*; 公共类中国实现人、DisposableBean { 私人斧斧; 中国公众() { System.out.println(“春实例化主调bean:中国实例…”); } 公共空间setAxe(斧斧) { System.out.println(“春天执行依赖关系注入…”); 这一点。斧=斧; } 公共空间useAxe () { System.out.println (axe.chop ()); } 公共空间close () { 系统。println(“正在执行销毁之前的方法密切…”); } 公共空间摧毁()抛出异常 { 系统。println(“正在执行销毁之前的方法破坏…”); } } >之前 2 SteelAxe
包org.crazyit.app.service.impl; 进口org.crazyit.app.service。*; 公共类SteelAxe实现斧 { 公共SteelAxe () { System.out.println(“春实例化依赖bean: SteelAxe实例…”); } 公共字符串切() { 返回“钢斧砍柴真快”; } } >之前
李包; 进口org.springframework.context。*; 进口org.springframework.context.support。*; 进口org.crazyit.app.service。*; 公开课中的BeanTest { 公共静态void main (String [] args) {//以类路径路径下的配置文件创建ApplicationContext AbstractApplicationContext ctx=new ClassPathXmlApplicationContext(“它指明”);//获取容器中的Bean实例 p=ctx的人。Person.class getBean(“中国”); p.useAxe ();//为春容器注册关闭钩子 ctx.registerShutdownHook (); } } >之前
春实例化依赖bean: SteelAxe实例…
引用>
春天实例化主调bean:中国实例…
春天执行依赖关系注入……
钢斧砍柴真快
2019年九月21日9:30:18下午,org.springframework.context.support。ClassPathXmlApplicationContext doClose
信息:Closing org.springframework.context.support。ClassPathXmlApplicationContext@5a10411:启动日期(坐2019年9月21日21:30:18 CST);根of 上下文层次
正在执行销毁之前的方法摧毁……
正在执行销毁之前的方法关闭…更多关于java相关内容感兴趣的读者可查看本站专题:《春天框架入门与进阶教程》、《java数据结构与算法教程》、《java操作DOM节点技巧总结》,《java文件与目录操作技巧汇总》和《java缓存操作技巧汇总》
希望本文所述对大家java程序设计有所帮助。
春天实战之豆销毁之前的行为操作示例