I have been using request scoped beans for my application and I'm curious to know how spring stores those kind of beans in the application context? is there a http reuqest id linked to it? any help/documentation is most welcomed as I did not find much about it.
1 Answers
Each Scope
is has its own implementation which knowns how and where objects are stored. The request scope, implemented by the RequestScope
, stores the object in the request attributes (see sources).
What Spring does when it finds a scoped bean (i.e. bean with @Scope
or specific annotation like @RequestScope
, @SessionScope
) is to create a proxy of that object. The proxy will do a lookup of the actual object instance (or create it and store it) using the earlier mentioned Scope
instance. It will then pass on the method call to actual the instance.
You can check this by looking at an @Autowired
scoped bean and you will see that it is actually a proxy instead of a real instance.
The current request is accessible in Spring through the RequestContextHolder
.

- 115,695
- 22
- 220
- 224
-
would you happen to know where the bean look up code is in the spring git project? :) – Sophian Achiba Jun 11 '18 at 22:03