Chapter 28. Examples for Chapter 14
Java EE and Spring. In this chapter, there are two similar examples that define the services il-
lustrated in Chapter 2 . The first marries JAX-RS with EJB. The second uses Spring to write
our JAX-RS services. Instead of using in-memory maps like the earlier examples in the
workbook, both examples use the Java Persistence API (JPA) to map Java objects to a rela-
Example ex14_1: EJB and JAX-RS
This example shows how you can use JAX-RS with EJB and JPA. It makes use of some of
the integration code discussed in Chapter 14 .
To implement ex14_1 , the Wildfly 8.0 Application Server is used to deploy the example.
Wildfly is the community version of the JBoss application server. It is Java EE 7-compliant,
so JAX-RS 2.0 is already built in. As a result, our Maven pom.xml file needs to change a
little to support this example. First, let's look at the dependency changes in this build file:
<groupId> org.jboss.resteasy </groupId>
<artifactId> resteasy-jaxrs </artifactId>
<version> 3.0.5.Final </version>
<scope> provided </scope>
Because JAX-RS 2.0 is built in, we do not have to add all the RESTEasy third-party depend-
encies to our WAR file. The provided scope is used to tell Maven that the JAR dependen-
cies are needed only for compilation and to not include them within the WAR.
Next, we need to include a Wildfly Maven plug-in:
<groupId> org.jboss.as.plugins </groupId>
<artifactId> jboss-as-maven-plugin </artifactId>
<version> 7.1.1.Final </version>