Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>beanManager#getReference</strong> gives you a new instance of a client proxy but the client proxy will forward method calls to the current contextual instance of a particular context. Once you obtain the proxy and keep it and the method calls will be invoked on the current instance (e.g. current request). It is also useful if the contextual instance is not serializable - the client proxy will be and will reconnect after you deserialize it.</p> <p><strong>BeanManager#getContext</strong> obtains the target instance without a client proxy. You may still see a Weld's proxy in the class name but that is an enhanced subclass that provides interception and decoration. If the bean is not intercepted nor decorated this will be a plain instance of the given bean.</p> <p>Usually (1) is more suitable unless you have a special use-case where you need to access the target instance directly (e.g. to access its fields).</p> <h2>Or in other words</h2> <p><strong>1) BeanManager#getReference</strong> will return a 'Contextual Reference', with a normal scoping proxy for the bean. If a bean have with <code>@SessionScoped</code> as </p> <pre><code>@SessionScoped User user; </code></pre> <p>Then the contextual reference user will 'point' to the respective User instance (the 'Contextual Instance') of the <em>current</em> session for each invocation. Two different invocations to <code>user.getName()</code> from two different web browsers will give you different answers.</p> <p><strong>2) Context#get()</strong> will return a the internal 'Contextual Instance' without the normal scoping proxy.This is usually nothing a user should call himself. If you get the <code>User user</code> for "Bob" that way and store it in an <code>@ApplicationScoped</code> bean or in a static variable, then it will always remain to be the user "Bob" - even for web requests from other browsers! You will get a direct, non-proxied instance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload