In the context of the study, Spring encountered the afterPropertiesSet() and destroy() methods of the InitializingBean and DisposableBean interfaces, respectively. I implemented two of these interfaces in my Class and implemented both of the above methods in it.
When creating a bean, the afterPropertiesSet() initialization method successfully executes. Tell me how to initiate a call to the destroy() method of the DisposableBean interface? I can not understand.
http://www.springframework.org/schema/beans/spring-beans.xsd "default-lazy-init =" true ">
<bean id="t1000" class="ru.javabegin.training.spring.impls.robot.ModelT1000" scope="prototype"> <constructor-arg value="silver" index="0" type="String"/> <constructor-arg value="2006" index="1" type="int"/> <constructor-arg value="true" index="2" type="boolean"/> <property name="hand" ref="toshibaHand" /> <property name="leg" ref="toshibaLeg"/> <property name="head" ref="toshibaHead"/> </bean> <bean id="t1000Empty" class="ru.javabegin.training.spring.impls.robot.ModelT1000"> <constructor-arg ref="sonyHand"/> <constructor-arg ref="sonyLeg"/> <constructor-arg ref="toshibaHead"/> </bean> <bean id="t1000P" class="ru.javabegin.training.spring.impls.robot.ModelT1000"> <constructor-arg value="silver" index="0" type="String"/> <constructor-arg value="2006" index="1" type="int"/> <constructor-arg value="true" index="2" type="boolean"/> </bean> <bean id="sonyHand" class="ru.javabegin.training.spring.impls.sony.SonyHand" /> <bean id="sonyHead" class="ru.javabegin.training.spring.impls.sony.SonyHead"/> <bean id="sonyLeg" class="ru.javabegin.training.spring.impls.sony.SonyLeg"/> <bean id="toshibaHand" class="ru.javabegin.training.spring.impls.toshiba.ToshibaHand" scope="prototype"/> <bean id="toshibaHead" class="ru.javabegin.training.spring.impls.toshiba.ToshibaHead" /> <bean id="toshibaLeg" class="ru.javabegin.training.spring.impls.toshiba.ToshibaLeg" /> Below are the afterPropertiesSet () and destroy () methods in the bin, which implements the initializing Initial and DisposableBean int-sy:
public void destroy() throws Exception { System.out.println(this + " method Destroy()"); } public void afterPropertiesSet() throws Exception { System.out.println(this + " method Init()"); }
destroy()is called at the end of execution. and if it is necessary in the middle of a program, can it simply be called as a method? - Senior Pomidor