Git Product home page Git Product logo

tmplt-server-rest-jersey's Introduction

Jersey REST Server Template

Description

The goal of this template is to have a basic Jersey server, ready to be run in Tomcat. The Spring configuration is based on annotations, no XML context files! The server can respond with XML or JSON.

It is not easy to find correct versions of jersey-server and jersey-spring3 that work well together. For newer versions of Jersey (3.1, 3.1.1) I could not find a correct Spring integration bundle. As long as the integration problems persist it is impossible to use a newer version of Jersey ...

I can only get it working with Jackson JSON not with Jettison.

Features

  • Standard Java web application.
  • REST services.
  • Spring configuration (annotation based).

Usage

Adding a service

  • Don't forget to put the packages that Jersey has to scan in the web.xml as wel (servlet parameter). It is only necessary if you want to add other packages that are not subpackages of the main package com.sdicons.
  • Just add the service with correct annotations, Jersey will automatically find it. You don't need to register the service class anywhere. It cannot be simpler. The service class must have a @Path annotation as well, otherwise the Jersey scanner will not find the resource.

Notes

  • At least Java 1.6 needed for the Spring annotations.
  • In Spring +3.1 @ComponentScan becomes available, so you do not need to create the beans explicitly.
  • You should run it as a Tomcat application. It was tested with Tomcat 6 and 7.

Links

Files

  • /README.txt: This file
  • /pom.xml: The Maven configuration file.
    1. Spring core (main Spring functionality) + web (for the context listener that creates the global Spring context).
    2. Jersey Server + Jersey Spring integration.
    3. Jackson for JSON rendering trough JAXB annotations.
  • /src/main/java/com/sdicons/AppConfig.java: The Spring configuration class replacing the XML configuration. It produces all the application instances.
  • /src/main/java/com/sdicons/RestService.java: A plain JAX-RS 'hello' service..
  • /src/main/webapp/WEB-INF/web.xml: Standard Java web application.
    1. Jersey servlet + parameter to scan package for resources.
    2. Spring context setup to pick up our AppConfig class to initialize the context.

Conclusions

Jersey automatically finds resources and providers in the registered packages. So you don't have to register the classes in different places.

Jersey currently does not integrate well with Spring. You could stick to the version in this POM, but it can be very frustrating if you want to upgrade version to get a bugfix or a neew feature and you cannot do it because the Spring injection wont work anymore. This is a good reason not to use Jersey for a product that will be in use for a number of years.

I worked very hard to integrate Jettison as well, but I did not succeed. There was no way to get the Jettison integration working. This should be an easy task to do. I think that the Jersey project is aiming towards the JSON-P which will be in Java 8+. It is unfriendly towards older, existing projects.

tmplt-server-rest-jersey's People

Watchers

James Cloos avatar Purushottam Kumar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.