JAX-RS (REST)No Comments

This tutorial show you how to integrate Jersey web application with Spring framework.

Technologies used :

  1. Jersey 1.8
  2. Spring 3.0.5.RELEASE
  3. Eclipse 3.6
  4. Maven 3

1. Project Dependency

Declares Jersey 1.8, Spring3 and “jersey-spring.jar” dependencies in Maven pom.xml file.

In “jersey-spring.jar” version, it will download all the Spring 2.5.6 dependencies. To use Spring 3, you need to exclude those old Spring libraries manually.

  • Spring Bean

A simple “transactionBo” bean is registered in Spring Ioc container. Later you will inject this bean into Jersey service.

File : applicationContext.xml – Register bean and enable the component auto scanning feature.

  • Jersey

In REST method, you can to auto inject the “transactionBo” bean from Spring into Jersey.

  • Integrate Jersey with Spring

The core integration is in web.xml

  1. Register Spring “ContextLoaderListener” listener class
  2. Change Jersey servlet from “com.sun.jersey.spi.container.servlet.ServletContainer” to “com.sun.jersey.spi.spring.container.servlet.SpringServlet“.

File : web.xml


Be the first to post a comment.

Add a comment