Comparison and analysis of Spring MVC and Jax-rs

Source: Internet
Author: User
Tags comparison web services

Introduction

Over the past few years, rest has become an important concept that affects the design of web frameworks, Web protocols, and Web applications.

It is not surprising that more and more companies now want to expose web APIs in ways that are simple and fit the Web architecture itself, so rest becomes more and more important. The rich browsers that use Ajax to communicate are also moving towards this goal. This architectural principle increases the scalability of the World Wide Web, and can benefit from this principle in any application.

Jax-rs (JSR 311) refers to the Java API for RESTful Web Services,roy Fielding was also involved in the development of JAX-RS, and he defined rest in his doctoral thesis. For developers who want to build restful Web services, Jax-rs gives another solution different from Jax-ws (JSR-224). At present, there are 4 kinds of JAX-RS implementations, all of which support Spring,jersey is JAX-RS reference implementation, is also the implementation of this article.

If you are using spring for development, you might want to know (or have been asked) the similarities and differences between spring MVC and Jax-rs. Further, if you have a spring MVC application in hand, using Control class inheritance (Simpleformcontroller, etc.), you may not be aware of the current spring MVC's extensive support for rest.

This article describes the rest features in spring 3 and compares them with Jax-rs, hoping to help you straighten out the similarities and differences between the two programming models.

Before you begin, it is necessary to point out that the goal of JAX-RS is Web services development (which is different from HTML Web applications) and the goal of Spring MVC is web application development. Spring 3 adds extensive rest support for Web applications and Web services, but this article focuses on features related to Web services development. I think this approach is more helpful in discussing spring MVC in the context of Jax-rs.

The 2nd thing to illustrate is that the REST features we're going to discuss are part of the spring framework and are a continuation of the existing Spring MVC programming model, so there is no such thing as the Spring REST framework. Some are just spring and spring MVC. This means that if you have a spring application, you can either create an HTML Web layer using spring MVC or create a RESTful Web services layer.

About the code fragment in the article

The code snippet in this article assumes a simple domain model: Two JPA annotation entities, account and Portfolio, one of which corresponds to multiple Portfolio. The persistence layer uses the spring configuration, which includes a JPA warehousing implementation for capturing and persisting entity instances. Jersey and spring MVC are used to build the Web services layer to service client requests by invoking the underlying spring managed application.

Bootstrapper and Web Layer Wrapper

We use spring to implement dependency injection in spring MVC and Jax-rs. Spring MVC Dispatcherservlet and Jersey springservlet the request to the rest layer component (Controller or resource) that spring manages, which is packaged by business or persistence layer components, as shown in the following illustration:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.