Skip to main content

Disambiguating two EJBs in an .ear file

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
5 replies [Last post]
ljnelson
Offline
Joined: 2003-08-04

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 instead of .

<?xml version="1.0" ?>

XBean

XBean/y

YBean

For some reason, I've always had trouble parsing the EJB specification on
this point.

Thanks,
Laird

--
http://about.me/lairdnelson

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04

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:

sless2
Session
SlessEJB2

com.sun.s1asdev.ejb.ejb30.hello.session2full.SfulEJB
sless2

-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 instead of .
>
> <?xml version="1.0" ?> 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">
>
>
>
>
> XBean
>
>
>
> originally declared via annotations -->
> XBean/y
>
> like injected into that reference -->
> YBean
>
>
>
>
>
>
> For some reason, I've always had trouble parsing the EJB specification
> on this point.
>
> Thanks,
> Laird
>
> --
> http://about.me/lairdnelson

ljnelson
Offline
Joined: 2003-08-04

On Fri, Jun 21, 2013 at 10:31 AM, Marina Vatkina
wrote:

> defines a reference to another EJB that will be looked up.
>

Ah, OK, but does not...does not *per se* cause the injection to happen; for
that I need to specify the stuff. Right?

Must I also specify the , if it is already implicitly
declared by my use of annotations? I would think not.

Revised attempt:

XBean

XBean/y
YBean
**
* foo.XBean*
* y*
* *

Best,
Laird

--
http://about.me/lairdnelson

ljnelson
Offline
Joined: 2003-08-04

One further question in this area.

While happily screwing things up, I ran across this error (to be clear: the
error is my fault):

Caused by: com.sun.enterprise.container.common.spi.util.InjectionException:
Exception attempting to inject *Remote* ejb-ref name=foo.XBean/y,*Remote
3.x interface =foo.Y*,ejb-link=YBean,lookup=,mappedName=,jndi-name=,refType=Session
into class foo.XBean: Lookup failed for 'java:comp/env/foo.XBean/y' in
SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory,
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,
java.naming.factory.url.pkgs=com.sun.enterprise.naming}

Note all the "remote" stuff. This is despite the fact that none of the
interfaces in my application are @Remote. Why is that?

Best,
Laird

--
http://about.me/lairdnelson

mvatkina
Offline
Joined: 2005-04-04

Are you using or ? The latter is for remote.

-marina

On 6/21/13 12:20 PM, Laird Nelson wrote:
> One further question in this area.
>
> While happily screwing things up, I ran across this error (to be
> clear: the error is my fault):
>
> Caused by:
> com.sun.enterprise.container.common.spi.util.InjectionException:
> Exception attempting to inject *Remote* ejb-ref
> name=foo.XBean/y,*Remote 3.x interface
> =foo.Y*,ejb-link=YBean,lookup=,mappedName=,jndi-name=,refType=Session
> into class foo.XBean: Lookup failed for 'java:comp/env/foo.XBean/y' in
> SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory,
> java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,
> java.naming.factory.url.pkgs=com.sun.enterprise.naming}
>
> Note all the "remote" stuff. This is despite the fact that none of
> the interfaces in my application are @Remote. Why is that?
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson

mvatkina
Offline
Joined: 2005-04-04

On 6/21/13 10:52 AM, Laird Nelson wrote:
> On Fri, Jun 21, 2013 at 10:31 AM, Marina Vatkina
> > wrote:
>
> defines a reference to another EJB that will be
> looked up.
>
>
> Ah, OK, but does not...does not /per se/ cause the injection to
> happen; for that I need to specify the stuff. Right?
>
> Must I also specify the , if it is already implicitly
> declared by my use of annotations? I would think not.

It's optional, and the spec doesn't require it "the target enterprise
bean must be of the type indicated in the ejb-ref-type element, if present".

>
> Revised attempt:
>
> XBean
>
> XBean/y

It should be >y<
> YBean
> **
> *foo.XBean*
> *y*
> * *
>
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson