此内容没有您所选择的语言版本。

17.2. Pluggable JAXBContexts with ContextResolvers


We do not recommend using this feature unless you are familiar with the principles involved.
By default, RESTEasy creates and caches JAXBContext instances per class type depending on the class you are marshaling or unmarshaling. If you do not want RESTEasy to create JAXBContexts, you can plug in your own by implementing an instance of javax.ws.rs.ext.ContextResolver.
 public interface ContextResolver<T>
 {
T getContext(Class<?> type);
 }

 @Provider
 @Produces("application/xml")
 public class MyJAXBContextResolver implements ContextResolver<JAXBContext>
 {
JAXBContext getContext(Class<?> type)
{
   if (type.equals(WhateverClassIsOverridedFor.class)) return JAXBContext.newInstance()...;
}
 }
You must provide a @Produces annotation to specify the types of media intended for the context. You must also implement ContextResolver<JAXBContext>. This helps the runtime match the correct context resolver. You must also annotate the ContextResolver class with @Provider.
There are several ways to make this ContextResolver available.
  1. return it as a class or instance from a javax.ws.rs.core.Application implementation.
  2. list it as a provider with resteasy.providers.
  3. let RESTEasy automatically scan for it within your WAR file. (See the Configuration Guide for more details.)
  4. add it manually via ResteasyProviderFactory.getInstance().registerProvider(Class) or registerProviderInstance(Object).
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部