在使用Spring的ApacheCXF中使用不同的JSON提供程序统一端点
背景 我们使用的是2.5.x、和 我们目前有两个端点,ABC和DEF,它们用作JSON提供程序。我们的Spring文件看起来像:在使用Spring的ApacheCXF中使用不同的JSON提供程序统一端点,spring,cxf,jax-rs,Spring,Cxf,Jax Rs,背景 我们使用的是2.5.x、和 我们目前有两个端点,ABC和DEF,它们用作JSON提供程序。我们的Spring文件看起来像: <bean id="jacksonMapper" class="org.codehaus.jackson.map.ObjectMapper" /> <bean id="jsonProvider"class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" p:mapper-ref="jacksonMap
<bean id="jacksonMapper" class="org.codehaus.jackson.map.ObjectMapper" />
<bean id="jsonProvider"class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" p:mapper-ref="jacksonMapper"/>
<jaxrs:server id="service1" address="/">
<jaxrs:serviceBeans>
<ref bean="resourceABC" />
<ref bean="resourceDEF" />
</jaxrs:serviceBeans>
<jaxrs:providers >
<ref bean="jsonProvider"/>
</jaxrs:providers>
</jaxrs:server>
但这不起作用。我们已经尝试在同一服务器元素中使用多个提供者
,但没有骰子
讨论如何使用serverFactories
元素。例如:
<beans>
<jaxrs:server id="customerService" address="/service1">
<jaxrs:serviceFactories>
<ref bean="sfactory1" />
<ref bean="sfactory2" />
</jaxrs:serviceFactories>
</jaxrs:server>
<bean id="sfactory1" class="org.apache.cxf.jaxrs.spring.SpringResourceFactory">
<property name="beanId" value="customerBean1"/>
</bean>
<bean id="sfactory2" class="org.apache.cxf.jaxrs.spring.SpringResourceFactory">
<property name="beanId" value="customerBean2"/>
</bean>
<bean id="customerBean1" class="demo.jaxrs.server.CustomerRootResource1" scope="prototype"/>
<bean id="customerBean2" class="demo.jaxrs.server.CustomerRootResource2" scope="prototype"/>
</beans>
这看起来很有希望,但是如何在春季为服务设置JSONprovider
,customerBean1
和customerBean2
问题
有人能澄清上面最后一种方法吗?我们能否用Gson而不是Jackson实现引入resourceIJK
(在同一个端点根)的目标
如果只能使用Apache CXF 2.7来完成,那么这是一个不错的有用信息。Hi!面对同样的问题。你是怎么解决这个问题的?
<beans>
<jaxrs:server id="customerService" address="/service1">
<jaxrs:serviceFactories>
<ref bean="sfactory1" />
<ref bean="sfactory2" />
</jaxrs:serviceFactories>
</jaxrs:server>
<bean id="sfactory1" class="org.apache.cxf.jaxrs.spring.SpringResourceFactory">
<property name="beanId" value="customerBean1"/>
</bean>
<bean id="sfactory2" class="org.apache.cxf.jaxrs.spring.SpringResourceFactory">
<property name="beanId" value="customerBean2"/>
</bean>
<bean id="customerBean1" class="demo.jaxrs.server.CustomerRootResource1" scope="prototype"/>
<bean id="customerBean2" class="demo.jaxrs.server.CustomerRootResource2" scope="prototype"/>
</beans>