Jetty and Spring EJB3 (Pitchfork)
Pitchfork is an add-on for the Spring Framework performing JSR-250 dependency injection, annotation processing and EJB 3.0-style interception, developed jointly by Interface21 and BEA Systems.
It is simple to use in conjunction with Jetty.
At the time of writing, the integration with Pitchfork is checked in to jetty svn trunk, but will be released with 6.1.0 final. Until then, it will be first necessary to checkout and build jetty.
Once jetty is built, make a new directory:
$jetty.home/lib/ext/spring. Copy the jar from
$jetty.home/extras/spring/target into it. Also copy all of the jars from the Pitchfork download into it.
Developing a webapp using EJB3
The JEE tutorial from Sun will take you through how to create EJB3 classes.
Here's an extremely simple example of a stateless session bean showing some of the JEE-style annotations:
We would declare this class in a
META-INF/spring-ejb-jar.xml file. That file can reside in a jar if you're packaging your ejbs into jars, or you can make a
WEB-INF/classes/META-INF/ directory if your ejbs are just part of your webapp.
The spring-ejb-jar.xml file for the above bean looks like:
Next, you can make some classes that use @EJB notation to inject references to your beans. Here's another stupidly simple class that uses the
In order to have Pitchfork notice that the
com.acme.EchoTest class wants a reference to the
com.acme.EchoBean ejb, we declare it in the Spring
Notice the very important second line with id jeeEjbPostProcessor. This line tells Pitchfork to look at all other <bean> declarations and perform any necessary resource injections on them.
To complete the webapp, here's a trivial jsp:
When you deploy it and surf to it, you'll see something like this:
A maven project that builds a deployble webapp for the example we've been looking at is attached to this page.