Consider the following request-scoped CDI bean:
@RequestScoped
public class RequestScopedBean {
// ...
}
Now, I inject it in a application-scoped bean:
@ApplicationScoped
public class ApplicationScopedBean {
@Inject private RequestScopedBean requestScopedBean;
// ...
}
I ran this code and noted that the request-scoped bean in开发者_如何学Cstance is different between two requests but the application-scoped bean instance is the same. My doubt is: how does this work? Is the request-scoped bean instance reattributed to the application-scoped field at each request? Or the proxy of the application-scoped bean just changes between requests?
In CDI each injected object is actually a proxy. So in that case, the proxy probably holds a reference to the RequestContext
and on each method invocation gets the correct bean instance.
精彩评论