Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 实现上下文解析器<;JAXBContext>;春天_Json_Spring_Jaxb_Jersey - Fatal编程技术网

Json 实现上下文解析器<;JAXBContext>;春天

Json 实现上下文解析器<;JAXBContext>;春天,json,spring,jaxb,jersey,Json,Spring,Jaxb,Jersey,因此,我正在编写一个Spring(2.5)(1.1.4.1)并尝试使用ContextResolver创建一个JSONConfiguration package com.rhigdon.jersey.config; import com.sun.jersey.api.json.JSONConfiguration; import com.sun.jersey.api.json.JSONJAXBContext; import javax.ws.rs.ext.ContextResolver; imp

因此,我正在编写一个Spring(2.5)(1.1.4.1)并尝试使用ContextResolver创建一个JSONConfiguration

package com.rhigdon.jersey.config;

import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;

@Provider
public final class JAXBContextResolver implements ContextResolver<JAXBContext> {
  private JAXBContext context;

  public JAXBContextResolver() throws Exception {
    this.context = new JSONJAXBContext(JSONConfiguration.mappedJettison().build(), "com.rhigdon.core.model.");
  }

  public JAXBContext getContext(Class<?> aClass) {
    return context;
  }
}
package com.rhigdon.jersey.config;
导入com.sun.jersey.api.json.json配置;
导入com.sun.jersey.api.json.JSONJAXBContext;
导入javax.ws.rs.ext.ContextResolver;
导入javax.ws.rs.ext.Provider;
导入javax.xml.bind.JAXBContext;
@提供者
公共最终类JAXBContextResolver实现ContextResolver{
私有JAXBContext上下文;
公共JAXBContextResolver()引发异常{
this.context=newJSONJAXBContext(JSONConfiguration.MappedDestinson().build(),“com.rhigdon.core.model”);
}
公共JAXBContext getContext(类aClass){
返回上下文;
}
}
不幸的是,我的应用程序仍在返回默认映射:

{“id”:“1”,“问题”:“这是/曾经是什么?” 您的第一只宠物的名字?}

当我调试应用程序时,它从未真正命中此代码。这是因为使用了SpringServlet吗?这是我的web.xml中的Jersey配置:

<servlet>
    <servlet-name>Jersey Spring Web Application</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Spring Web Application</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

Jersey Spring Web应用程序
com.sun.jersey.spi.spring.container.servlet.SpringServlet
Jersey Spring Web应用程序
/*

任何人都有类似的JSONConfiguration设置吗?

您需要在spring上下文中注册您的提供者:

<bean class="com.company.jersey.config.JAXBContextResolver"/>

到您的应用程序上下文配置。

我使用的是jersey版本1.10,没有@Component注释和bean定义,没有它也可以工作。


泽西岛休息服务
com.sun.jersey.spi.spring.container.servlet.SpringServlet
com.sun.jersey.config.property.packages C.C.C.SA.EZFW.Fask.WebService 1

这是一个非常明显的解决方案,但我想回答,以防其他人像我一样头脑空白。:)这个答案如何帮助解决问题?请解释你的答案。不要强迫人们在不想使用Spring的时候使用Spring。
<context:annotation-config />
<context:component-scan base-package="com.company.jersey" />