Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring 4 vs Jersey for REST web services

People also ask

What is difference between Jersey and spring REST?

Jersey is the JAX-RS API example implementation provided by Sun, while Spring REST is of course Spring's implementation of the same API/JSRs. The major difference is that Spring REST easily integrates into other Spring APIs (if you wish) such as Spring Data Rest.

Which is better Jersey or spring boot?

Using Spring Boot and JerseySpring Boot provides the spring-boot-starter-jersey module that allows you to use the JAX-RS programming model for the REST endpoints instead of Spring MVC. It works quite well with Jersey 2. x. For a complete example of creating a web application with Jersey 2.

Is spring GOOD FOR REST API?

Advantages of using Spring Boot Spring Boot is a Java framework, built on top of the Spring, used for developing web applications. It allows you to create REST APIs with minimal configurations. A few benefits of using Spring Boot for your REST APIs include: No requirement for complex XML configurations.

What is Jersey RESTful web services?

Jersey RESTful Web Services framework is open source, production quality, framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation. Jersey framework is more than the JAX-RS Reference Implementation.


I'd say both Jersey and Spring MVC are great - each project has its own style and strengths. Anyway, Stack Overflow is not the right place for asking subjective comparisons (your question would be closed quite quickly). If you're already using Spring for everything else and are not required to use JAX-RS, then Spring MVC makes total sense.

Regarding features like (un)marshalling, JAX-RS is just a spec after all - other libraries can offer similar features without implementing the same API.

  1. Instead of MessageBodyReaders/Writers, Spring MVC is using HttpMessageConverters to handle (un)marshalling REST resources. Spring MVC handles content negotiation and chooses the best available converter for the job (you can annotate methods to hint at what media type they produce/consume).

  2. No, it's not necessary to use JAX-RS to (un)marshall resources. In fact, JAX-RS implementations and Spring MVC use third party serialization libraries to do the job; so it's not tied to a particular standard.

  3. In its 4.0.6 version, Spring supports many HttpMessageConverters, with Jackson for JSON, JAXB for XML and many others. Spring 4.1.0 added more HttpMessageConverters:

    • Jackson is now available for both JSON and XML
    • Google Protobuf
    • Gson for JSON, as an alternative to Jackson

To answer your last point, @XmlRootElement is a JAXB annotation and is not part of JAX-RS. Spring supports JAXB.

For a more complete example with REST in Spring, check out this getting started guide (you'll get a complete example running in 10-15 minutes).

Again the last part of your question is quite subjective - there are many popular solutions for building REST services in the JVM, not just Jersey and Spring (Dropwizard, Play! Framework, etc).


AFAIK Spring REST support is based on Spring MVC and its not JAX-RS implementation while Jersey has implemented JAX-RS specification. Those having Spring (Core, AOP or MVC) in their project chooses Spring ReST support over JAX-RS implementor.

I recommend Jersey as its mature, implements JAX-RS and is easy to use.