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.
cassiomolin Mar 22 '17 at 15:08 2017-03-22 15:08
source share