ejb-ref has been created by David Blevins (May 16, 2008).

Content:

Via annotation

Usable by EJB, Interceptor, Servlet, Filter, or Listener
package org.superbiz.refs;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.naming.InitialContext;

@Stateless
@EJB(name = "myFooEjb", beanInterface = FooRemote.class)
public class MyEjbRemoteRefBean implements MyBeanInterface {

    @EJB
    private BarRemote myBarEjb;

    public void someBusinessMethod() throws Exception {
        if (myBarEjb == null) throw new NullPointerException("myBarEjb not injected");

        // Both can be looked up from JNDI as well
        InitialContext context = new InitialContext();
        FooRemote fooRemote = (FooRemote) context.lookup("java:comp/env/myFooEjb");
        BarRemote barRemote = (BarRemote) context.lookup("java:comp/env/org.superbiz.refs.MyEjbRemoteRefBean/myBarEjb");
    }
}

Via xml

The above @EJB annotation usage is 100% equivalent to the following xml.

ejb-jar.xml or web.xml
<ejb-ref>
    <ejb-ref-name>myFooEjb</ejb-ref-name>
    <remote>org.superbiz.refs.FooRemote</remote>
</ejb-ref>
<ejb-ref>
    <ejb-ref-name>org.superbiz.refs.MyEjbRemoteRefBean/myBarEjb</ejb-ref-name>
    <remote>org.superbiz.refs.BarRemote</remote>
    <injection-target>
        <injection-target-class>org.superbiz.refs.MyEjbRemoteRefBean</injection-target-class>
        <injection-target-name>myBarEjb</injection-target-name>
    </injection-target>
</ejb-ref>

Powered by Atlassian Confluence (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request

Unsubscribe or edit your notifications preferences