1.
1 public class HelloWorld { 2 private String msg; 3 public void setMsg(String msg) { 4 this.msg = msg; 5 } 6 public String getMsg() { 7 return msg; 8 } 9 public void detory(){ 10 this.msg=""; 11 } 12 }
<bean id="HelloWord" class="com.ltf.captha.serviceImpl.HelloWorld" destroy-method="destory"> <property name="msg"> <value>helloworld</value> </property> </bean>
2. 实现org.springframework.beans.factory.DisposableBean中的destory方法
public class HelloWorld implements DisposableBean{ private String msg; public void setMsg(String msg) { this.msg = msg; } public String getMsg() { return msg; } public void destroy() throws Exception { this.msg=""; } }