Truly there is no difference in implementation. Integrating Spring with Jersey and integrating Jersey with Spring 
Tags: rest, sping, jersey, java
Published: 2020-04-07 02:54:55


More interesting and arguably references are Jersey and Spring, especially  integrating Jersey to Spring, or differ. This article we might response that curiosity. [Catch up source code which we implemented Spring and Jersey.] (https://github.com/Hamdambek/SpringBoot-Projects-FullStack/tree/master/Part-4%20Spring%20Boot%20REST%20API) 
    Really there is no difference in implementation. Integrating Spring with
    Jersey and integrating Jersey with Spring mean the same thing as far as code 
    is concerned. 
# What is Jersey, stands for...?

Briefly inform about Jersey: The 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.
# What is JAX-RS...?

Java API for RESTful Web Services (JAX-RS) is a Java programming language API specification that provides support in creating web services according to the Representational State Transfer (REST) architectural pattern.
JAX-RS uses annotations to simplify the development and deployment of web service clients and endpoints. JAX-RS is an official part of Java EE.

This article assumes you understand Jersey, and are thinking about integrating Spring into your Jersey application. Figure-1. Three-tier application architecture.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/uqvr69zi0mlvh2eh8459.jpg)

Figure-1. Three-tier application architecture.

In this example, the business layer and persistence layer may seem redundant, but in a real application, the service layer also handles the business logic of the domain, not just a simple “find data”, but also “do manipulate data”. The persistence layer should only be concerned with database interactions, and not with any business logic.
In a REST application, there is no presentation layer. But does that mean that this architecture doesn’t apply to REST applications? Absolutely not. We should still adhere to this separation of concerns in REST applications. It is just good design.
With Spring, its REST layer is implemented in its MVC framework. The MVC framework is widely know for its MVC capabilities with the use of controllers. But with a little tweaking of the controllers and the annotations used, the controllers can easily become a REST controller, where instead of return models and views, you are return RESTful representation objects. More valuable information adhere Figure-2. A multi-layered architecture, based on the “Law of Demeter". 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/a9ajrzoiacc8tycm10t7.jpg)
Figure-2. Multi-layer architecure.

   * the first layer is the REST support implemented with Jersey, has the role of a facade and delegates the logic to the business layer
   * the business layer is where the logic happens
   * the data access layer is where the communcation with the pesistence storage (in our case the MySql database) takes place


[Source code:] (https://github.com/Hamdambek/SpringBoot-Projects-FullStack/tree/master/Part-4%20Spring%20Boot%20REST%20API)
  
     @SpringBootApplication
     public class JerseyApplication implements WebApplicationInitializer {

      public static void main(String[] args) {
        SpringApplication.run(JerseyApplication.class, args);
      }

      @Override
     public void onStartup(ServletContext sc) throws ServletException {
        sc.setInitParameter("contextConfigLocation", "noop");

        AnnotationConfigWebApplicationContext context
                = new AnnotationConfigWebApplicationContext();
        context.register(SpringConfig.class);
        sc.addListener(new ContextLoaderListener(context));
        sc.addListener(new RequestContextListener());
     }


Reference:

1. [WHY AND HOW TO USE SPRING WITH JERSEY?] (https://psamsotha.github.io/jersey/2015/10/19/why-use-spring-with-jersey.html#mavenDeps)
2. [Tutorial – REST API design and implementation in Java with Jersey and Spring] (https://www.javacodegeeks.com/2014/08/tutorial-rest-api-design-and-implementation-in-java-with-jersey-and-spring.html)