Springboot of Jax-rs and Jersey

Source: Internet
Author: User

Springbott support jersey, if jersey2.x only need to rely on Spring-boot-starter-jersey.

Then you need to configure ResourceConfig

@Component  Public class extends ResourceConfig {    public  jerseyconfig () {        Register (Endpoint. class );    }}

Endpoint class to have @components and HTTP resource annotations (@Get, etc.)

@Component @path ("/hello")  Public class Endpoint {    @GET    public  String message () {        return "Hello";    }} 

Because endpoint is a component of Spring (Component) and is managed by spring, you can inject its properties through @autowired and inject configuration values through @value.

The Jersey Servlet will match/* By default, and you can restrict it by adding @applicationpath to ResourceConfig.

The default jersey is built in a servlet in the class Servletregistrationbean corresponding Bean, which is named Jerseyservletregistration. By default, the servlet is lazy loaded, and you can customize it by using the Spring.jersey.servlet.load-on-startup property. You can override the above bean by creating a bean of your own class and giving him the same name as above.

You can also set the filter order by Spring.jersey.filter.order by setting the property spring.jersey.type=filter to Jersey as a filter instead of a servlet ( Corresponding to the servlet's @order).

Both the filter and the servlet can pass initialization parameters through spring.jersey.init.*.

Click on the link to see the official Spring jersey example to get an overview of how to create a Jersey project.

Springboot of Jax-rs and Jersey

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.