Spring session-scoped beans as dependencies in prototype beans?

前端 未结 1 948
耶瑟儿~
耶瑟儿~ 2021-01-31 06:21

I read spring docs on this subject several times, but some things are still unclear to me. Documentation states:

If you want to inject (for example) an HT

相关标签:
1条回答
  • 2021-01-31 06:46

    You can always inject a bean of wider scope (e.g. a singleton) into a bean of narrower scope (e.g. a session-scoped bean), but to it the other way around, you need a scoped-proxy.

    So your example of injecting a session-scoped bean into a prototype-scoped bean is fine, because session-scope is "wider" than prototype-scope.

    If you get it wrong, then Spring will tell you. If it doesn't complain, then you don't need it.

    0 讨论(0)
提交回复
热议问题