问题
How to inject a session scoped bean into another session scoped bean without proxy?
@Component
@Scope("session")
class Foo {
@Inject Bar bar;
}
@Component
@Scope("session")
class Bar {
}
It reports error "No matching bean". Though a TARGET_CLASS scope-proxy could resolve this problem, but why do I need a proxy for same scoped beans?
回答1:
My guess is - because at the injection point spring doesn't distinguish injected beans depending on the scope of the current bean. It needs a proxy to fetch the target bean (from the session in this case), disregarding the scope of the bean where it's injected into.
来源:https://stackoverflow.com/questions/7991114/scoped-bean-inject-one-into-another