2
votes

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
Out of curiosity, what happens if you use @Autowired instead of @Inject?skaffman
You need to include more information, wiring session-scoped beans between beans of the same scope works fine without proxies. I assume in your code @Component is spelled correctly? Is your Bar class picked up by the component scan?mrembisz
@mrembisz: Yes, it's @Component, my mistake. to include more information - how?Xiè Jìléi

1 Answers

0
votes

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.