servlet容器中使用jersey 翻译官网
来源:互联网 发布:点击按钮执行php代码 编辑:程序博客网 时间:2024/06/11 07:28
Servlet 2.x Container
<pre name="code" class="html"><!--jersey 2.x用以下依赖,但2.6以后的版本都是用是JDK7,所以要注意版本问题--> <dependency > <groupId >org.glassfish.jersey.containers </groupId> <!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" --> <artifactId >jersey-container-servlet </artifactId> <version >2.5 </version></dependency><!-- Required only when you are using JAX-RS Client --><dependency> <groupId >org.glassfish.jersey.core </groupId> <artifactId >jersey-client </artifactId> <version >2.5 </version></dependency>
web.xml 基础配置两种实现方式
<web-app> <servlet> <servlet-name>MyApplication</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> ... </init-param> </servlet> ... <servlet-mapping> <servlet-name>MyApplication</servlet-name> <url-pattern>/myApp/*</url-pattern> </servlet-mapping> ...</web-app>
利用过滤器:
Alternatively, you can register Jersey container as a filter:
Example 4.10. Hooking up Jersey as a Servlet Filter
<
web-app
>
<
filter
>
<
filter-name
>MyApplication</
filter-name
>
<
filter-class
>org.glassfish.jersey.servlet.ServletContainer</
filter-class
>
<
init-param
>
...
</
init-param
>
</
filter
>
...
<
filter-mapping
>
<
filter-name
>MyApplication</
filter-name
>
<
url-pattern
>/myApp/*</
url-pattern
>
</
filter-mapping
>
...
</
web-app
>
<init-param>
element will vary depending on the way you decide to configure Jersey resources.Example 4.12. Configuring Jersey container Servlet or Filter to use package scanning
<
init-param
>
<
param-name
>jersey.config.server.provider.packages</
param-name
>
<
param-value
>
org.foo.myresources,org.bar.otherresources
</
param-value
>
</
init-param
>
<
init-param
>
<
param-name
>jersey.config.server.provider.scanning.recursive</
param-name
>
<
param-value
>false</
param-value
>
</
init-param
>
jersey.config.server.provider.scanning.recursive
true
, i.e. the recursive scanning of sub-packages is enabled.3、扩展配置(不需要可以不配置)4.7.1.1. Custom Application
subclass
If you extend the Application class to provide the list of relevant root resource classes (getResources()
) and singletons (getSingletons()
),
i.e. your JAX-RS application model, you then need to register it in your web application web.xml
deployment descriptor
using a Servlet or Servlet filter initialization parameter with a name ofjavax.ws.rs.Application
[sic] as follows:
Example 4.11. Configuring Jersey container Servlet or Filter to use custom Application
subclass
<
init-param
>
<
param-name
>javax.ws.rs.Application</
param-name
>
<
param-value
>org.foo.MyApplication</
param-value
>
</
init-param
>
Jersey will consider all the classes returned by getResources()
and getSingletons()
methods of your Application
implementation.
Note
javax.ws.rs.Application
and not javax.ws.rs.core.Application
as one might expect.
importorg.glassfish.jersey.server.ResourceConfig;
importorg.glassfish.jersey.server.spring.scope.RequestContextFilter;
publicclassMyapplicationextendsResourceConfig{
publicMyapplication(){
register(RequestContextFilter.class);
register(Hello.class);
}
}
在Myapplication中暴漏资源
Servlet 2.x Container
<!--jersey 2.x用以下依赖,但2.6以后的版本都是用是JDK7,所以要注意版本问题-->
web.xml 基础配置两种实现方式
<
web-app
>
<
servlet
>
<
servlet-name
>MyApplication</
servlet-name
>
<
servlet-class
>org.glassfish.jersey.servlet.ServletContainer</
servlet-class
>
<
init-param
>
...
</
init-param
>
</
servlet
>
...
<
servlet-mapping
>
<
servlet-name
>MyApplication</
servlet-name
>
<
url-pattern
>/myApp/*</
url-pattern
>
</
servlet-mapping
>
...
</
web-app
>
利用过滤器:
Alternatively, you can register Jersey container as a filter:
Example 4.10. Hooking up Jersey as a Servlet Filter
<
web-app
>
<
filter
>
<
filter-name
>MyApplication</
filter-name
>
<
filter-class
>org.glassfish.jersey.servlet.ServletContainer</
filter-class
>
<
init-param
>
...
</
init-param
>
</
filter
>
...
<
filter-mapping
>
<
filter-name
>MyApplication</
filter-name
>
<
url-pattern
>/myApp/*</
url-pattern
>
</
filter-mapping
>
...
</
web-app
>
<init-param>
element will vary depending on the way you decide to configure Jersey resources.Example 4.12. Configuring Jersey container Servlet or Filter to use package scanning
<
init-param
>
<
param-name
>jersey.config.server.provider.packages</
param-name
>
<
param-value
>
org.foo.myresources,org.bar.otherresources
</
param-value
>
</
init-param
>
<
init-param
>
<
param-name
>jersey.config.server.provider.scanning.recursive</
param-name
>
<
param-value
>false</
param-value
>
</
init-param
>
jersey.config.server.provider.scanning.recursive
property.true
, i.e. the recursive scanning of sub-packages is enabled.3、扩展配置(不需要可以不配置)4.7.1.1. Custom Application
subclass
If you extend the Application class to provide the list of relevant root resource classes (getResources()
) and singletons (getSingletons()
), i.e.
your JAX-RS application model, you then need to register it in your web application web.xml
deployment descriptor using a Servlet or Servlet filter
initialization parameter with a name ofjavax.ws.rs.Application
[sic] as follows:
Example 4.11. Configuring Jersey container Servlet or Filter to use custom Application
subclass
<
init-param
>
<
param-name
>javax.ws.rs.Application</
param-name
>
<
param-value
>org.foo.MyApplication</
param-value
>
</
init-param
>
Jersey will consider all the classes returned by getResources()
and getSingletons()
methods of your Application
implementation.
Note
The name of the configuration property as defined by JAX-RS specification is indeed javax.ws.rs.Application
and not javax.ws.rs.core.Application
as one might expect.
importorg.glassfish.jersey.server.ResourceConfig;
importorg.glassfish.jersey.server.spring.scope.RequestContextFilter;
publicclassMyapplicationextendsResourceConfig{
publicMyapplication(){
register(RequestContextFilter.class);
register(Hello.class);
}
}
在Myapplication中暴漏资源
- servlet容器中使用jersey 翻译官网
- 在Servlet Filter中使用Spring容器
- 在Servlet Filter中使用Spring容器
- Jersey中ContainerRequestFilter的使用
- 在IDEA中使用maven-jetty-plugin作为servlet容器
- Jersey使用中遇到的问题
- springmvc 中使用Jersey上传图片
- 使用 Spring 容器管理 Servlet
- 使用 spring 容器管理 Servlet
- 使用ServletContextListener监听servlet容器
- 使用 Spring 容器管理 Servlet
- jersey使用
- org.glassfish.jersey.servlet.ServletContainer
- 在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- 在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- 在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- 在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- (转)在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- HDU 1862 EXCEL排序 (排序水题)
- 继续畅通工程
- Android学习Scroller(四)——实现拉动后回弹的布局
- 继承、方法重写和多态
- ACM练级日志:POJ 3074 数独与DLX
- servlet容器中使用jersey 翻译官网
- 接口框架等知识点小结
- Jungle Roads
- 第七章 复用类
- ls
- Web和非Web下获取根目录的方法
- 各大内存数据库系统对比
- 处堵午睡
- ubuntu使用小记