Hi all,
I would like to destroy / cleanup a bean that has its target set as a
ThreadLocalTargetSource object. I am using ApplicationContext to create the
mentioned bean. What's the best way to cleanup only the ThreadLocal bean?
I could call ApplicationContext.destroy() but it would close the context and
destroy all singletons. Is it approximate to get a reference to
ThreadLocalTargetSource and cast it to DisposableBean and invoke destroy()
directly? If so, how do I do it?
Here's my config:
On another note, I was checking the ThreadLocalTargetSourceCode:<bean id="sessionManager" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces" value="foo.SessionManager"/> <property name="targetSource"> <bean class="org.springframework.aop.target.ThreadLocalTargetSource"> <property name="targetBeanName" value="sessionManagerImpl"/> </bean> </property> </bean> <bean id="sessionManagerImpl" class="foo.SessionManagerImpl" singleton="false"/>
source and the way it's clearing the ThreadLocal variable is like this:
Shouldn't we call this.targetInThread.set(null) instead?Code:public void destroy() { ......... this.targetSet.clear(); // clear ThreadLocal this.targetInThread = null; }
Thanks for your help!
Vincent


Reply With Quote