I was reading the specification regarding the use of ejb-ref and ejb-local-ref in the deployment descriptors, and I was still confused about one thing. I hope somebody in here can help me out a bit. My question: what happens when ejb-link is not specified by the application assembler? I would hope that the server could do its magic and find the correct EJB by looking at the home and remote (or local) interface types. But since the specification states that those interfaces can have superinterfaces, I can put those in the ejb-ref subelements and still be okay. At that point, which EJB will actually be bound to my ref is ambiguous at this point, right? Any thoughts?
Nathaniel, The container will not deploy an application with unresolved ejb references. Within the application's scope there might be several beans conforming to the ejb-ref's home/remote/local interface, and the container doesn't have enough information to pick the right one. Thus the application deployer must (manually) resolve all links prior to actual deployment. -Ade Barkah
I agree that's what should happen. But, the specification says that the application assembler MAY use ejb-link to specify an EJB, but not necessarily. Heck, even in the DTD, the ejb-link element is optional. Are you saying that by the time it is actually deployed, the ejb-link element MUST be specified? By the way, do you know this from any portion of the specification, or just from observed behavior of application servers out there? I couldn't find any mention of what would happen if ejb-link is not given, nor any mention that it had to be specified by the time the application was deployed.
By the time the application is actually deployed, all ejb-refs must be bound to real JNDI names either directly, or through ejb-links if any. Section 20.3.3 of ejb-2_0-fr2-spec reads in part:
The Deployer must ensure that all the declared EJB references are bound to the homes of enterprise beans that exist in the operational environment. The Deployer may use, for example, the JNDI LinkRef mechanism to create a symbolic link to the actual JNDI name of the target enterprise bean's home. ... If an EJB reference declaration includes the ejb-link element, the Deployer should bind the enterprise bean reference to the home of the enterprise bean specified as the link's target.
In 3.1.3, the spec required the Deployer to resolve all external dependencies declared by the Bean Provider. Further, in 20.3.4, the spec requires container deployment tools to inform the Deployer of any "unresolved EJB references" and allow him or her to resolve it. So if the Bean Provider specifies an ejb-ref, then a) the Assembler may resolve the reference using ejb-link; or failing that, b) the Deployer must resolve the reference, using a container-specific mechanism. Here's a concrete example using Weblogic: (ejb-jar.xml)
If the Application Assembler doesn't specify a link, then the Deployer must bind the reference using a weblogic-specific mechanism: (weblogic.xml)
-Ade Barkah Edit: part of post was missing, trying again. [ April 05, 2004: Message edited by: Ade Barkah ]