Spring and Jersey Integration Example

This tutorial explains how to write a simple example using Spring and Jersey. This example uses Jersey for the REST implementation, Spring is used for managing the beans. In my previous tutorial, I have explained how to write a simple REST application using Jersey. We also can use Spring alone for implementing the RESTful web services.

1. Add Jersey and Spring JAR files

Look at the below picture for the list of JARs added for this application


2. Create a Spring Bean

package org.jersey.examples;

public class SpringBeanExample{
	public String getValue(){
		return "Spring and Jersey Integration";

3. Create Jersey Service

package org.jersey.examples;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

public class JerseySimpleExample {
	SpringBeanExample springBean;

	public Response getMessage() {
		String result = springBean.getValue();
		return Response.status(200).entity(result).build();

4. Spring Configuration XML

<context:component-scan base-package="org.jersey.examples" />
<bean id=0"springBean" class="org.jersey.examples.SpringBean" />

5. Web.xml Configuration

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>Jersey Example</display-name>



About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.


  1. Arilson says:

    Hello Krishna,

    I’d like to take a winsdow yours.
    I’m using Spring but I don’t know yet witch implementation to use.
    Jersey, CXF or any of both?



  2. sherabc says:

Speak Your Mind