-
1. Re: Best practice for injecting components from other EARs?
barakka Oct 19, 2009 6:24 PM (in response to lanroth)Unfortunately, you're a bit out of luck. Automatic injection for EJB works only with EJBs from same Ear (at least on JBoss, where the JNDI name uses a pattern that includes the ear name), as Seam does the lookup accordingly with the JNDI pattern, which necessarily either works for your own EJB or for an external EJB.
The suggested pattern is to use the @Unwrap
factory
. Basically you have a component that does the lookup in the normal JNDI way and returns the EJB in a method annotated with @Unwrap. If you name such seamfactory
component with the same name you'd like to use for the injectintion, then something like @In ContentManagerServiceBean contentManagerService; would start to work.Your class would therefore be something like:
@Name("contentManagerService") public class ContentManagerServiceFactory { ... @Unwrap public ContentManagerService serviceFactory(){ // do JNDI lookup // Return the object obtained. }
Of course you can put the lookup in an init method, and cache the way you prefer the reference to the
remote
EJB, scope it as you like etc.The other option is to configure the JNDI pattern of all EJBs (from your ear and from the external one) to use the same pattern and then to configure it in the seam app.
Hope it helps,
Riccardo. -
2. Re: Best practice for injecting components from other EARs?
lanroth Oct 21, 2009 11:54 AM (in response to lanroth)Hi Riccardo,
Thank you very much for your help - that worked perfectly :-)
Cheers,
Steve