Scoped bean: inject one into another

不打扰是莪最后的温柔 提交于 2019-12-11 01:33:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!