Title: EJB Refs
## Referencing a bean in another jar (with annotations)
When using annotations to reference a bean from another ejb in your ear you
have to supplement the @EJB reference with a small chunk of xml in the
ejb-jar.xml of the referring bean.
So in ejb app A colorsApp.jar you have this bean:
package com.foo.colors;
import javax.ejb.Stateless;
@Stateless
public class OrangeBean implements OrangeRemote {
}
Then in ejb app B shapesApp.jar you have this bean with a reference to
OrangeRemote:
package com.foo.shapes;
import javax.ejb.Stateless;
import com.foo.colors.OrangeRemote;
@Stateless
public class SquareBean implements SquareRemote {
@EJB OrangeRemote orangeRemote;
}
To hook this reference up you need to override this ref and add more info
in the ejb-jar.xml of shapesApp.jar as follows:
SquareBean
com.foo.shapes.SquareBean/orangeRemote
colorsApp.jar#OrangeBean
## Referencing a bean in another jar (xml only, no annotations)
The same basic approach applies and dependency injection is still possible,
however more information must be described in the xml.
In ejb app A colorsApp.jar you have this bean:
package com.foo.colors;
import javax.ejb.Stateless;
@Stateless
public class OrangeBean implements OrangeRemote {
}
Then in ejb app B shapesApp.jar -- note there is no @EJB annotation:
package com.foo.shapes;
import javax.ejb.Stateless;
import com.foo.colors.OrangeRemote;
@Stateless
public class SquareBean implements SquareRemote {
OrangeRemote orangeRemote;
}
Here's how you would hook this reference up, injection and all, with just
xml. The following would be added to the ejb-jar.xml of shapesApp.jar:
SquareBean
com.foo.shapes.SquareBean/orangeRemote
Session
com.foo.colors.OrangeRemote
colorsApp.jar#OrangeBean
com.foo.shapes.SquareBean
orangeRemote
Note that the value of could actually be anything and the
above example would still work as there is no annotation that needs to
match the and no one will likely be looking up the EJB as
it's injected.