Home > Database > Mysql Tutorial > body text

jersey1.X与jersey2.X的区别

WBOY
Release: 2016-06-07 15:43:12
Original
1598 people have browsed it

1:web.xml加载jersey的servlet容器 jersey1.X使用的是sun的com.sun.jersey.spi.container.servlet.ServletContainer jersey2.X使用的是glassfish的org.glassfish.jersey.servlet.ServletContainer 2: 扫描 jersey resource jersey1.X使用的是sun的com.sun.

1:web.xml加载jersey的servlet容器

jersey1.X使用的是sun的com.sun.jersey.spi.container.servlet.ServletContainer

jersey2.X使用的是glassfish的org.glassfish.jersey.servlet.ServletContainer


2:扫描jersey resource

jersey1.X使用的是sun的com.sun.jersey.config.property.packages

jersey2.X使用的是glassfish的jersey.config.server.provider.packages


3:jersey2.X可以使用servlet3的 @WebServlet扫描jersey resource。不需要特别配置web.xml


例如:

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可以使用@ApplicationPath注解,加载jersey resouce。

例如:

@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可以使用web.xml加载Application

             

Jersey Web Application

org.glassfish.jersey.servlet.ServletContainer

javax.ws.rs.Application

com.example.RestApplication

1

Jersey Web Application

/webapi/*


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!