Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Spring SimpleThreadScope?

Tags:

java

spring

Spring 3.0 defines a SimpleThreadScope. Looking at all known implementing classes of the Scope interface, I see: AbstractRequestAttributesScope, PortletContextScope, RequestScope, ServletContextScope, SessionScope, SimpleThreadScope.

The first observation is that I don't see a PrototypeScope, and don't understand why.

My question, though, is how to use SimpleThreadScope, since RequestScope becomes "request" in XML or annotation, so I tried to use "simplethread" and "simpleThread", but they don't work.

I get the following message:

Caused by: java.lang.IllegalStateException: No Scope registered for scope 'simpleThread'
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)

Does it mean that SimpleThreadScope should be used only programmatically, not through XML or annotations? And how to use it?

like image 710
stivlo Avatar asked Sep 30 '11 09:09

stivlo


1 Answers

SimpleThreadScope is not registered by default, so that you need to register it manually in order to use it, see 3.5.5.2 Using a custom scope.

singleton and prototype scopes don't have their Scope classes since they are hardcoded into bean factory.

like image 189
axtavt Avatar answered Oct 06 '22 03:10

axtavt