标签:yellow class stat org ext.get print pre ioc context
销毁方法:只有当对象被销毁之后,才执行destroy方法,只有关闭的时候才会销毁
<!-- destroy-method:销毁方法,在调用的方法之后执行(当对象被销毁的时候执行) --> <bean id="yelloMouseWolf" class="cn.java.ioc1.YelloMouseWolf" init-method="init" destroy-method="destroy"></bean>
public void destroy() { //销毁方法 System.out.println("销毁方法"); }
package cn.java.ioc1; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class window { public static void main(String[] args) { //1.启动框架,context代表spring容器 ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); //2.获取spring容器中创建的对象,通过xml中的id值获取 YelloMouseWolf yellow1 = (YelloMouseWolf) context.getBean("yelloMouseWolf"); yellow1.behavior(); //3.关闭context容器,并销毁容器中的所有对象 ((ClassPathXmlApplicationContext)context).close(); } }
标签:yellow class stat org ext.get print pre ioc context
原文地址:https://www.cnblogs.com/lonske/p/9057489.html