Remote EJBs and Seam 2.2.0 Injection

Feb 17 2010

In this blog I'm going to talk about using remote EJBs that are contained in a seperate deployment than your Seam 2.2.0 components.  Note that for accessing local EJBs in the same EAR there's a much simpiler way to go about it, detailed in the Seam documentation.  For discrete deployments however, say, a WAR and an EAR, we need to do some plumbing to take advantage of Seam's bijection features.  

Essentially we need to write a service locator Seam component that will look up the remote EJB in JNDI and inject it into the Seam context for our other componets to use.  This isn't as bad as it sounds thanks to the Seam Factory Component pattern:

 

 

 

 

 

 

 

 

 

 

 

 

Note the use of @Factory instead of @Unwrap.  By using @Factory we avoid having to write a separate Seam component for each service. 

With this locator component deployed we can now use @In to inject our remote services into Seam components, just as if they were components themselves.  To add new services we simply add a method to the locator with the proper JNDI name specified. 

Now, with that said, if you have the ability to make your Seam components EJBs deployed in an EAR, you should in theory be able to use the standard @EJB injection mechanism, forgoing the extra plumbing above.  I haven't tested this method, so YMMV.

About the Author

Matt Kesler's picture

Matt Kesler is a CapTech Senior Consultant interested in JavaEE and web development.

 

Disclaimer

The words and opinions expressed here are those of each article's respective author, and do not necessarily represent the views of CapTech Ventures.