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