Jersey the RESTful Web Services in Java

Source: Internet
Author: User
Tags representational state transfer

Jersey is a JAX-RS implementation, Jax-rs Java API for RESTful Web Services, which supports the creation of a WEB service according to the Representational state Transfer (REST) architectural style. The most important concept in REST is resources, which are identified by using the global ID (usually URI). The client application uses the HTTP method get/post/put/delete to manipulate the resource or resource set. RESTful Web services are Web services that are implemented using HTTP and REST principles. In general, RESTful Web Services should define the following:

The base/root URI of the Web service, such as Http://host/<appcontext>/resources
Supports MIME-type response data, including Json/xml/atom, etc.
A collection of operations supported by the service, such as POST, GET, PUT, or delet.


JAX-RS provides an abstract class for deployment detection application for declaring root resources and providing corresponding classes, which can be deployed without the need for Web. XML on containers that support Servlets 3.0 and above. You only need to use @applicationpath on a class and extend the application

@ApplicationPath ("/*")publicclassextends  application {    @Override      Public Set<class<?>> getclasses () {        Setnew hashset<class<?>>();        S.add (Helloworldresource. class );         return s;    }    ...}

and Jersey provides its own way to make it easier to use its advanced features

@ApplicationPath ("Resources")publicclassextends  resourceconfig {      public MyApplication () {        packages ("org.foo.rest;org.bar.rest");}    }

Add Failonmissingwebxml in Pom.xml to avoid missing web. XML errors in the build

<Plugins>    ...    <plugin>        <groupId>Org.apache.maven.plugins</groupId>        <Artifactid>Maven-war-plugin</Artifactid>        <version>2.3</version>        <Configuration>            <Failonmissingwebxml>False</Failonmissingwebxml>        </Configuration>    </plugin>    ...</Plugins>

In the initialization method of MyApplication (),

Packages ("Com.aa.bb", "com.aa.cc"); You can provide multiple package paths for automatic scanning. These paths are the resource classes that Mark @Path, @Produces, @GET, and so on.

Register () method for registering various components

Jersey the RESTful Web Services in Java

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.