SimpleThreadScope
という名前のカスタムスコープを使用できます。
Spring
ドキュメントから:Spring 3.0
のよう
、スレッドスコープが利用可能ですが、デフォルトで に登録されていません。詳細については、 SimpleThreadScopeのドキュメントを参照してください。これを登録する方法や他のカスタムスコープを に追加する方法については、3.5.5.2, “Using a custom scope”を参照してください。
ここ
SimpleThreadScopeスコープを登録する方法の例:
Scope threadScope = new SimpleThreadScope();
beanFactory.registerScope("thread", threadScope);
その後、あなたはあなたのBeanの定義でそれを使用することができます:
<bean id="foo" class="foo.Bar" scope="thread">
あなたはまた、行うことができますスコープ登録申告:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<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>
<bean id="foo" class="foo.Bar" scope="thread">
<property name="name" value="bar"/>
</bean>
</beans>