Cover by Bill Burke

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Example ex11_2: Spring and JAX-RS

There isn’t much difference between the code of ex11_1 and ex11_2. The Java classes are basically the same, except the @Stateless annotations were removed from the JAX-RS resource classes because the example is using Spring instead of EJB for its component model. For the same reason, the EJBExceptionMapper class isn’t needed anymore.

Besides the removal of EJB metadata, the differences between the two projects are mainly packaging and configuration. If you look through the ex11_2 directory, you’ll see that we’re back to using embedded Jetty and a single WAR project. The web.xml file is a bit different than the EJB example, so let’s take a look at that first:

src/main/webapp/WEB-INF/web.xml

<web-app>
...

    <env-entry>
        <env-entry-name>spring-beans-file</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-type>
        <env-entry-value>
               META-INF/applicationContext.xml
        </env-entry-value>
    </env-entry>


</web-app>

This example follows the Spring integration conventions discussed in Chapter 11. The web.xml file adds an <env-entry> to point to the Spring XML file that holds all of the example’s Spring configuration. Let’s look at this Spring XML file:

src/main/resources/applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required