Difference Between JAX-RS and Spring Vacations

I mixed up the difference between JAX-RS (well, maybe you should use Jersey for comparison, since JAX-RS is just a specification) and Spring for Restful services . I tried to find more information on the Internet and it became more confusing. My company uses Spring MVC to develop a Restful API

It is confusing that JAX-RS stands for Java API for RESTful Web Services , spring I also use java to develop RESTful Web Services, so in fact I do not understand the differences. Does Spring meet JAX-RS specifications?

From what I know so far:

  1. JAX-RS is a project / specification, it uses Jersey, RESTeasy, etc. as implementations.
+107
spring-mvc jersey jax-rs
Mar 22 '17 at 7:01
source share
4 answers

Jax-rs

JAX-RS is a specification for implementing Java REST web services currently defined by Java EE , which are currently defined by JSR 366 .

Jersey (supplied with GlassFish and Payara) is the reference implementation of JAX-RS, but there are other implementations such as RESTEasy (supplied with JBoss EAP and WildFly) and Apache CXF (supplied with TomEE and WebSphere).

Spring framework

Spring Framework is a complete framework that allows you to create Java applications. The REST capabilities are provided by the Spring MVC module (the same module that provides the capabilities of the model controller). This is not a JAX-RS implementation, and can be seen as an alternative to Spring's JAX-RS standard.

The Spring ecosystem also provides a wide range of projects for creating enterprise applications covering persistence, security, social media integration, batch processing, etc.

Examples

Consider the following resource controller using the JAX-RS API:

@Path("/greetings") public class JaxRsController { @GET @Path("/{name}") @Produces(MediaType.TEXT_PLAIN) public Response greeting(@PathParam("name") String name) { String greeting = "Hello " + name; return Response.ok(greeting).build(); } } 

Equivalent implementation using Spring MVC API:

 @RestController @RequestMapping("/greetings") public class SpringRestController { @RequestMapping(method = RequestMethod.GET, value = "/{name}", produces = MediaType.TEXT_PLAIN_VALUE) public ResponseEntity<?> greeting(@PathVariable String name) { String greeting = "Hello " + name; return new ResponseEntity<>(greeting, HttpStatus.OK); } } 

Using Spring Boot and Jersey

Spring Boot provides a spring-boot-starter-jersey module that allows you to use the JAX-RS programming model for REST endpoints instead of Spring MVC. It works great with Jersey 2.x.

For a complete example of creating a web application using Jersey 2.x and Spring Boot 1.4.x, refer to this.

+116
Mar 22 '17 at 15:08
source share

Annotation differences

(As of 2018) Spring MVC is not standardized for JAX-RS annotations since its solution precedes JAX-RS. Here are the equivalents:

enter image description here

https://stormpath.com/blog/jax-rs-vs-spring-rest-endpoints

If you use non-standard APIs, you should expect them to become obsolete and possibly be replaced by a newer experimental API in a few years. Regarding backward compatibility, there is much less responsibility (for example, when new versions of the JDK are released).

+34
Apr 16 '18 at 18:49
source share

I worked with Jersey Rest, Spring Break and Jersey Rest with spring. Both of them are very rich frameworks with good implementations. I would suggest using Spring rest better if you use other Spring services like ORM, Spring Security, DI, etc. Both are Spring libraries, so it's a little easier for me to manage code and dependencies

JAX-RS Pros:

  • The JSR standard can be run without a servlet container (grizzly, simple, ...)
  • Ready-to-implement implementations (knitwear, cxf, resteasy, restlet, ...) is for REST applications only

Spring MVC Professionals:

  • Provide a "full" stack, not just REST tools

  • Dependency Injection / AOP / Transactions

  • Replaceable presentation templates (JSP, freemarker, speed, ...)

You can check more at the following links

  1. https://www.infoq.com/articles/springmvc_jsx-rs
  2. Why use JAX-RS / Jersey?
+20
Mar 22 '17 at 13:08
source share

JAX-RS - specification and knitwear, etc. - this is its implementation. People use Spring to create RestFul web services, since Spring along with a quiet implementation provides things like sleep mode integration, as well as things like IOC and Aspect-oriented programming.

Where, as if we used knitwear for our implementation, the problem will be that the data must be extracted from the back using some ORM technologies, and we will have to write the template code for the same.

It is for this reason that people and even enterprises use Spring, as with the implementation of Rest, it also provides Spring tools. And now, using the latest Spring download, we can start development very quickly without a lot of configurations.

+4
Mar 22 '17 at 7:10
source share



All Articles