3

I encountered with this question in one of the interviews. Can we inject request scoped bean to session scoped bean and vice versa.Explain?

2 Answers2

0

When you take a look and Spring Documentation, you need to use proxying for these web scopes.

If you are using it correctly, there is proxy instance injected into new bean. And when you perform the call, proxy will resolve it to current session/scope instance of the bean.

So it should work fine, you just need to know at what stage the instance behind proxy is replaced.

Injecting request scope bean into session scope bean doesn't make sense, because there will always be new request for that session.

luboskrnac
  • 23,973
  • 10
  • 81
  • 92
0

It is possible to inject @RequestScope bean into @SessionScope.

Explanation is given here https://stackoverflow.com/a/26311504/4820148

Community
  • 1
  • 1
Jakub Hesoun
  • 108
  • 1
  • 6