Difference between jersey1.X and jersey2.X

Source: Internet
Author: User
Tags glassfish
1: web. jersey1.X, the servlet container for loading jersey in xml, uses sun's com. sun. jersey. spi. container. servlet. servletContainerjersey2.X uses org of glassfish. glassfish. jersey. servlet. servletContainer2: Scan jerseyresourcejersey1.X to use sun's com. sun.

1: web. jersey1.X, the servlet container for loading jersey in xml, uses sun's com. sun. jersey. spi. container. servlet. servletContainer jersey2.X uses org of glassfish. glassfish. jersey. servlet. servletContainer 2: Scan jersey resource jersey1.X using sun's com. sun.

1: web. xml loads jersey's servlet container

Jersey1.X uses sun's com. sun. jersey. spi. container. servlet. ServletContainer

Jersey2.X uses org. glassfish. jersey. servlet. ServletContainer of glassfish.


2: Scan jersey resource

Jersey1.X uses sun's com. sun. jersey. config. property. packages

Jersey2.X Uses jersey. config. server. provider. packages of glassfish.


3: jersey2.X scan jersey resource using @ WebServlet of servlet3. No special web. xml configuration is required


For example:

Import javax. servlet. annotation. WebInitParam;

Import javax. servlet. annotation. WebServlet;

Import org. glassfish. jersey. servlet. ServletContainer;

@ WebServlet (initParams = @ WebInitParam (name = "jersey. config. server. provider. packages ", value =" com. example "), urlPatterns ="/webapi/* ", loadOnStartup = 1)

Public class AirServlet extends ServletContainer {

Private static final long serialVersionUID = 1L;

}


4: jersey2.X can use the @ ApplicationPath annotation to load jersey resouce.

For example:

@ ApplicationPath ("/webapi /*")

Public class AirApplication extends Application {

@ Override

Public Set > GetClasses (){

Final Set > Classes = new HashSet > ();

Classes. add (MyResource. class );

Return classes;

}

}

5: jersey2.X can use web. xml to load the Application.

Jersey Web Application

Org. glassfish. jersey. servlet. ServletContainer

Javax. ws. rs. Application

Com. example. RestApplication

1

Jersey Web Application

/Webapi /*

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.