Jersey Spring Integration

Jersey spring integration tutorial is all about integrating jersey with spring. Most of the spring applications requires REST Web Services  at back end for mobile/UI, so  they may use Spring MVC framework/Jersey to generated REST web services. In addition, Jersey applications requires Service & data base layer, hence spring come in picture to manage dependencies.

So, How to integrate jersey with spring?  further to this tutorial, below are prerequisite tutorials:


  • Eclipse Mars
  • Spring 4
  • Jersey 1.19
  • Maven 4

Spring Jersey Tutorial:

  • Jersey requires only jersey-server jar, but for spring requires jersey-spring dependency jar
  •  Add com.sun.jersey.spi.spring.container.servlet.SpringServlet in web.xml that com.sun.jersey.spi.container.servlet.ServletContainer.
  • Load  applicationContext  in web.xml as a context loader
  • Annotate Rest resource class with @Component to mark as Spring Bean.


  1. Create New Maven Project : File -> New -> Maven Project
  2. Select Simple archetype and give the below detailsJersey Spring Details
  3. pom.xml file: Click here to download pom
  4. Create Project structure like below:
    • : For REST Resource Controllers and create
    • : Service Layer
    • org.javasavvy.tutorial.dao : DAO layer
    • org.javasavvy.tutorial.entity : Database JPA entities
    • :   REST POJO classes
    • The project Structure will look like:
      Jersey Spring Maven Tutorial
  5. create applicationContext.xml file in src/main/resources folder as which would availe to classpath always:
    1. <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns=""
       <context:annotation-config />
       <context:component-scan base-package="" />
       <context:component-scan base-package="" /> 
       <context:component-scan base-package="org.javasavvy.tutorial.dao" /> 
  6. create web.xml with below contents:
    1. <web-app xmlns="" xmlns:xsi=""
         <!-- <listener>
              </listener> -->
  7. UserServiceImpl class is:  Services need to annotate with @Service and add @Transactional as to make this service as transactional aware.Spring @Service
  8. Rest Resource Controller is: Annotate this with @Component Spring annotation and you can inject spring beans like userService with @Autowired.Jersey Spring controller
  9. Now deploy the application in tomcat
  10. Enter the url in browser: http://localhost:8080/jersey-spring-tutorial/rest/user/user-info/1
    • Response:
      1. {"status":200,"message":"User info",

Hope this helps

Click here to download the code


In the Next Tutorial, We will see Jersey Spring 4 Hibernate Maven tutorial


  1. Hrishikesh


    Thank you very much the topic you explained is so clear and gave me a good idea on this.
    I appreciate your work and thought of sharing every minute details with all.

    1. Jayaram Pokuri (Post author)

      Thanks Hrishi

  2. Pingback: Jersey Spring Hibernate Example,jersey spring jpa example

  3. AntuanSoft

    Good Job, thanks

  4. mayan jain

    hello Sir ,

    i didn’t understand that why we change 2 things 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“.

    if we will not change these two thing then what happen and please explain what are uses of them.



Leave a Comment

Your email address will not be published. Required fields are marked *