PDA

View Full Version : Webapp with optional EJB build: Best practices?



Andreas Schildbach
Mar 18th, 2005, 11:05 AM
Hello everyone,

we are developing a web application which would run with Spring and Hibernate alone. However, unfortunately it is a requirement that we provide a Stateless Session Bean facade using remote interfaces.

We are thinking about developing and testing the application without EJB, which should be possible using the techniques described in the Spring Reference Manual (EJB Convenience classes and Service Locator proxy).

For the web application version, we can't use the OpenSessionInView pattern, because this won't work over the borders of the Session Facade. We'd have to open the Hibernate session in the Session Facade (or some "substitute" like a proxy in the non-EJB case).

We would have either one applicationContext (in the non-EJB case) or two applicationContexts (one for EJBs, one for Web module). In both cases, applicationContext(s) are assembled from several XML files.

Is there a good pattern for configuring such an application?
Has anybody done something similar?
Would you say that this is a way to go, or is it a complete no-go?

Regards,

Andreas

wpoitras
Mar 18th, 2005, 03:09 PM
This seems reasonable. I can imagine you can two flavors of the xml file which contains references to your business code:

1) beans which implement the business code
2) beans which implement the EJB stubs but have the same names as #1

So when you don't want to use EJB you create a jar file:
non-ejb.jar - Contains xml file #1 and all the business object classes and their interfaces. This is placed in your WEB-INF/lib directory.

When you do want to use EJB you have two jar files:
ejb-client.jar - Contains xml file #2 and all the interfaces used by those beans. This is deployed in WEB-INF/lib directory.
ejb-server.jar - Contains xml file #1 and all the business object classes plus the EJB beans (subclass of AbstractStatelessSessionBean) which use the business objects as implementation. This is built/deployed as an EJB.