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 illustrated 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 relational 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>
<dependency>
<groupId>
org.jboss.resteasy</groupId>
<artifactId>
resteasy-jaxrs</artifactId>
<version>
3.0.5.Final</version>
<scope>
provided</scope>
</dependency>
Because JAX-RS 2.0 is built in, we do not have to add all the RESTEasy third-party dependencies to our WAR file. The provided
scope is used to tell Maven that the JAR dependencies are needed only for compilation and to not include them within the WAR.
Next, we need to include a ...
Get RESTful Java with JAX-RS 2.0, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.