java - Spring's threadlocal bean is behaving like a singleton -
java - Spring's threadlocal bean is behaving like a singleton -
we're using spring 4.0.6.release, java 8, , tomcat our app hosting engine.
we have spring bean looks this:
@service @scope("thread") public class foo { private bar bar; public void setbar(bar bar){ this.bar = bar; } }
the problem when bean gets injected different threads, threads same bean. each thread doesn't it's own bean have expected. bean injected @autowired
. there else has done thread local bean?
i registered scope in xml this:
<bean class="org.springframework.beans.factory.config.customscopeconfigurer"> <property name="scopes"> <map> <entry key="thread"> <bean class="org.springframework.context.support.simplethreadscope"/> </entry> </map> </property> </bean>
there grab here, have additionally mention kind of proxy create on top of bean - proxy understands scope , manages bean underlying relevant scope. should work you:
@service @scope(value="thread", proxymode = scopedproxymode.target_class) public class foo {
java spring
Comments
Post a Comment