-1

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.

Lemmy
  • 2,437
  • 1
  • 22
  • 30
Sophian Achiba
  • 197
  • 1
  • 13

1 Answers1

3

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.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224