users@glassfish.java.net

Re: Multiple Stateless Session Bean + Local Interface +Injection

From: <glassfish_at_javadesktop.org>
Date: Mon, 09 Jul 2007 11:54:37 PDT

Yes, any number of distinct bean components can implement the same business interface.
In this case, there would be N distinct bean classes, each of which implements the same
interface.

The easiest way to retrieve an EJB reference in Java EE 5 is to annotate a field with the
@EJB annotation. E.g.

@EJB
private Foo foo;

Usually there isn't any additional information required to map the @EJB dependency to the
target bean since the typical case is that there is only one bean within the application that
exposes the Foo business interface. However, if there are multiple beans that expose the
same business interface, you merely need to add an additional attribute to @EJB to
tell the deployment system which one you want.

@EJB(beanName="Bean1")
private Foo foo;

The beanName() attribute contains the ejb-name of the target bean. ejb-name is either
declared via the ejb-name attribute in ejb-jar.xml or is derived from the component-defining
@Stateless/_at_Stateful annotations. If the @Stateless/_at_Stateful annotation on a bean
contains the name() attribute, that counts as its ejb-name. Otherwise, the ejb-name
is the unqualified class-name of the bean class.

One more thing to note is that the beanName() attribute of @EJB has exactly the same
semantics as the ejb-link attribute of ejb-ref/ejb-local-ref. You can find more information
on the relationship between @EJB and ejb-ref/ejb-local-ref in our EJB FAQ :

https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#EJB_ejb-ref_ejb_local_ref
[Message sent by forum member 'ksak' (ksak)]

http://forums.java.net/jive/thread.jspa?messageID=225773