users@glassfish.java.net

Re: Disambiguating two EJBs in an .ear file

From: Marina Vatkina <marina.vatkina_at_oracle.com>
Date: Fri, 21 Jun 2013 10:31:24 -0700

<ejb-local-ref> defines a reference to another EJB that will be looked up.

You can look at ejb devtests for examples - e.g. you can find this
snippet in the ejb-jar.xml in ejb30/hello/session2full:
      <ejb-ref>
        <ejb-ref-name>sless2</ejb-ref-name>
        <ejb-ref-type>Session</ejb-ref-type>
        <ejb-link>SlessEJB2</ejb-link>
        <injection-target>
<injection-target-class>com.sun.s1asdev.ejb.ejb30.hello.session2full.SfulEJB</injection-target-class>
<injection-target-name>sless2</injection-target-name>
        </injection-target>
      </ejb-ref>

-marina

On 6/21/13 9:29 AM, Laird Nelson wrote:
> I'd like to confirm that the following general approach is the right
> one (before I start digging into GlassFish errors :-)):
>
> I have a SLSB (of class foo.XBean with no explicitly assigned bean
> name, so its bean name is defaulted to "XBean"). XBean implements a
> @Local interface, X (in case it matters).
>
> It has this in it:
>
> @EJB
> private Y y;
>
> Standard stuff.
>
> Y in this case is a @Local interface of another SLSB, foo.YBean, of
> type @Local Y, packaged in the same .ear file.
>
> Deployment obviously works fine.
>
> Now suppose I add another Y implementor to the ear file:
> foo.UnwantedYBean. This is also, let's say, a @Local implementation of Y.
>
> So two @Local Y implementations in the same .ear file and in the case
> of XBean no way to distinguish them. Oops.
>
> Obviously and appropriately deployment fails.
>
> So now I want to make it so that my EJB named XBean injects a
> foo.YBean proxy into its y field so that deployment will be happy
> again. Let's say I can't do this in the annotations.
>
> Is the following deployment descriptor XML (located obviously in
> XBean's ejb jar file, in the META-INF directory--no tricks) supposed
> to do this? I've tried to simply duplicate the example on page 448 of
> the EJB 3.1 specification, but using <ejb-local-ref> instead of <ejb-ref>.
>
> <?xml version="1.0" ?> <ejb-jar
> xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1">
> <enterprise-beans>
> <session>
>
> <!-- The bean name of the EJB whose innards I'm affecting -->
> <ejb-name>XBean</ejb-name>
>
> <ejb-local-ref>
>
> <!-- The name of the EJB reference I need to "fill";
> originally declared via annotations -->
> <ejb-ref-name>XBean/y</ejb-ref-name>
>
> <!-- The bean name of the EJB in the same Java EE module I'd
> like injected into that reference -->
> <ejb-link>YBean</ejb-link>
>
> </ejb-local-ref>
> </session>
> </enterprise-beans>
> </ejb-jar>
>
> For some reason, I've always had trouble parsing the EJB specification
> on this point.
>
> Thanks,
> Laird
>
> --
> http://about.me/lairdnelson