Java Reference
In-Depth Information
JAX-RS EJB from your Application.getClasses() method. For example, let's say we
have this EJB bean class:
@Path ( "/customers" )
public class
class CustomerResourceBean
CustomerResourceBean implements
implements CustomerResource {
If you are manually registering your resources via your Application class, you must re-
gister the bean class of the EJB via the Application.getClasses() method. For example:
package com . restfully . shop . services ;
import ;
import ;
@ApplicationPath ( "/root" )
public class
class ShoppingApplication
ShoppingApplication extends
extends Application {
public Set < Class <?>> getClasses () {
HashSet < Class <?>> set = new
new HashSet < Class <?>>();
set . add ( CustomerResourceBean . class );
return set ;
Spring Integration
Spring is an open source framework similar to EJB. Like EJB, it provides a great abstraction
for transactions, persistence, and security. Further explanation of Spring is beyond the scope
of this topic. If you want more information on it, check out Spring: A Developer's Notebook
by Bruce A. Tate and Justin Gehtland (O'Reilly). Most JAX-RS implementations have their
own proprietary support for Spring and allow you to write Spring beans that are JAX-RS
web services. If portability is not an issue for you, I suggest that you use the integration with
Spring provided by your JAX-RS implementation.
There is a simple, portable way to integrate with Spring that we can talk about in this chapter.
What you can do is write an Application class that loads your Spring XML files and then
registers your Spring beans with JAX-RS through the getSingletons() method. First, let's
define a Spring bean that represents a customer database. It will pretty much look like the
CustomerResource bean described in EJB Integration :
Search WWH ::

Custom Search