Java Reference
In-Depth Information
Chapter 28. Examples for
Chapter 14
In
Chapter 14
,
you learned a bit about how JAX-RS fits in the grander scheme of things like
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-
tional database.
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
.
Project Structure
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:
pom.xml
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>
<groupId>
org.jboss.resteasy
</groupId>
</groupId>
<artifactId>
<artifactId>
resteasy-jaxrs
</artifactId>
</artifactId>
<version>
<version>
3.0.5.Final
</version>
</version>
<scope>
<scope>
provided
</scope>
</scope>
</dependency>
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.
</dependency>
Next, we need to include a Wildfly Maven plug-in:
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>
<groupId>
org.jboss.as.plugins
</groupId>
</groupId>
<artifactId>
<artifactId>
jboss-as-maven-plugin
</artifactId>
</artifactId>
<version>
<version>
7.1.1.Final
</version>
</version>
<executions>