Reputation: 987
I want to understand what is use of request scoped beans in spring? I know it lives only till the request is alive. But I can't think of any practical use.
Upvotes: 0
Views: 827
Reputation: 7098
It is what it is, you get a bean scoped for the current request. That means that whenever you ask the spring context to give you a specific bean which is request scoped, you will get different instances for different requests. If you ask for the same bean twice in the same request, you'll get the same instance as you would expect.
Please note that in order to use request scoped beans in a singleton bean (the default bean scope in Spring), you will need a scoped proxy. That means, you'll need to use a singleton proxy instance in your singleton beans that will actually delegate all method invocations to the per-request scoped instances of that type.
See this answer on spring scoped proxy bean for a very nice and detailed explanation.
Upvotes: 1