官术网_书友最值得收藏!

Java EE7 - JAX-RS with Jersey

JAX-RS was born as a result of Java Specification Request (JSR) 311. As the official definition says, the JAX-RS is the Java API for RESTful web services. It's a specification that provides support in creating web services according to the REST architectural pattern. JAX-RS uses Java annotations, introduced in Java SE 5, to simplify the development and deployment of web service clients and endpoints. From version 1.1 on, JAX-RS is an official part of Java EE. A notable feature of being an official part of Java EE is that no configuration is necessary to start using JAX-RS.

Java EE 7 with JAX-RS 2.0 brings several useful features, which further simplify the development of microservices. One of the most important new features of JAX-RS 2.0 is the support for hypermedia following the HATEOAS principle of REST. Jersey, a library from Oracle, is probably the most widely known library, which implements this specification.

Jersey is the reference implementation for the JSR 311 specification.

The Jersey implementation provides a library to implement RESTful web services in a Java servlet container. On the server-side, Jersey provides a servlet implementation which scans predefined classes to identify RESTful resources. Jersey makes it a lot easier to write RESTful services. It abstracts away a lot of the low level coding you will need to do yourself otherwise. Using Jersey, you do it in a declarative way. The servlet, registered in your web.xml file, analyzes the incoming HTTP request and selects the correct class and method to respond to this request. It finds the proper method to execute by looking at the class and method level annotations. Annotated classes can reside in different packages, but you can instruct a Jersey servlet via the web.xml to scan certain packages for annotated classes.

JAX-RS supports the creation of XML and JSON via the Java Architecture for XML Binding (JAXB). The Jersey implementation also provides a client library to communicate with a RESTful web service.

As we have said before, we develop JAX-RS applications using Java annotations. It's easy and pleasant to work with. Let's describe those annotations now.

主站蜘蛛池模板: 桃源县| 武陟县| 东乡| 柏乡县| 本溪市| 监利县| 五河县| 千阳县| 邵武市| 屯昌县| 西青区| 花莲市| 乌苏市| 南华县| 大渡口区| 石阡县| 桦南县| 长乐市| 枣强县| 商南县| 聂拉木县| 南溪县| 长兴县| 温泉县| 锦州市| 夹江县| 余庆县| 云南省| 青岛市| 曲沃县| 嘉善县| 东光县| 肥城市| 蕲春县| 景德镇市| 南华县| 凤凰县| 新泰市| 栾城县| 双流县| 象山县|