"org.apache.cxf.jaxrs.bus.providers"不工作 [英] "org.apache.cxf.jaxrs.bus.providers" not working

查看:95
本文介绍了"org.apache.cxf.jaxrs.bus.providers"不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用创建2个REST容器.我想保留一些常见的东西,例如JSON提供程序,验证拦截器,使用cxf总线的异常处理.下面是我的应用程序上下文.

I'm creating 2 REST containers using . I want to keep some common things like the JSON providers, validation interceptor, exception handling using a cxf bus. below is my application context.

<cxf:bus>
    <cxf:properties>
       <entry key="org.apache.cxf.jaxrs.provider" key-ref="busProviders"/>
    </cxf:properties>
</cxf:bus>

  <util:list id="busProviders">
    <ref bean="requestInterceptor"/>
    <ref bean="jsonProvider"/>
    <ref bean="exceptionHandler"/>
  </util:list>

<bean id="requestInterceptor" class="com.sample.interceptor.ServiceValidationInterceptor"/>
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
<bean id="exceptionHandler" class="com.sample.exception.ExceptionHandler" />

<!-- ======================== REST Container for Service1 ======================================= -->
 <jaxrs:server id="restContainer" address="/service1">
        <jaxrs:serviceBeans>
            <ref bean="endecaService"/>
        </jaxrs:serviceBeans>
        <jaxrs:inInterceptors>
            <ref bean="logInbound"/>
            <bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor">
            <property name="callbackParam" value="callback"/>
            </bean>
        </jaxrs:inInterceptors>
        <jaxrs:outInterceptors>
            <ref bean="logOutbound"/>
            <bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor">
            <property name="mediaType" value="application/json"/>
            </bean>
            <bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor">
            <property name="paddingEnd" value=")"/>
            </bean>
        </jaxrs:outInterceptors>   
  </jaxrs:server>  

  <!-- ======================== REST Container for Service2========================================== -->
<jaxrs:server id="restContainerForHelpcenter" address="/service2">
    <jaxrs:serviceBeans>
        <ref bean="helpCenter"/>
    </jaxrs:serviceBeans>
        <jaxrs:inInterceptors>
            <ref bean="logInbound"/>
            <bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor">
            <property name="callbackParam" value="callback"/>
            </bean>
        </jaxrs:inInterceptors>
        <jaxrs:outInterceptors>
            <ref bean="logOutbound"/>
            <bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor">
            <property name="mediaType" value="application/json"/>
            </bean>
            <bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor">
            <property name="paddingEnd" value=")"/>
            </bean>
        </jaxrs:outInterceptors> 
  </jaxrs:server>

如果我将上面的2个与2个服务bean合并为一个,则可以正常工作,但在这种情况下不行. 是否有人将cxf:bus功能用于2个不同的REST容器,请让我知道.

If I combine the above 2 into a single with 2 service beans, then it works fine, but not in this case. Has anybody used the cxf:bus feature for 2 different REST containers, please let me know.

推荐答案

漫长的故事

我有一个类似的问题:

The long story

I had a similar problem:

我想对JAX-RS服务bean使用自动发现,但是如果我在<jaxrs:server>标记内使用<jaxrs:providers>标记但不使用<jaxrs:serviceBeans>标记,则根本就不会使用自动发现.

I want to use autodiscovery for the JAX-RS service beans, but if I use a <jaxrs:providers> tag inside the <jaxrs:server> tag but no <jaxrs:serviceBeans> tag, autodiscovery is simply not used.

这意味着我还必须对JAX-RS提供程序使用自动发现,这对于位于我们基本软件包之下的两个(对于Spring组件扫描)来说并不困难,因为它们已经被注释了@Provider.但是,这对于Jackson来说并不容易(并且包括在Spring组件扫描中的很多理由,因为它会像
一样多).包中包含几个带注释的类).

This means I have to use autodiscovery for the JAX-RS providers as well, which wasn’t difficult for the two that are below our base package (for the Spring component scan) since they were already annotated @Provider. However, this doesn’t work as easily for Jackson (and there are good reasons to not include Jackson in the Spring component scan, as it will pick up too much as the package contains several annotated classes).

因此,我不得不挂断CXF总线上的Jackson提供商.我找到了无用的文档,以及您的帖子,这给了我部分答案.我确实需要多次咒骂,学习xsi:schemaLocation等所有知识,但是最后,我做到了:

So I had to hang up the Jackson provider on the CXF bus. I found the docs, which weren’t helpful, and your post, which gave me part of the answer. I did need several iterations of cursing, learning about xsi:schemaLocation and all that, but in the end, I did it:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
        <context:component-scan base-package="com.example.basepackage"/>
<!-- … -->
        <import resource="classpath:META-INF/cxf/cxf.xml"/>
        <jaxrs:server address="/"/>
        <bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
        <cxf:bus>
                <cxf:properties>
                        <entry key="org.apache.cxf.jaxrs.providers" value-ref="busProviders"/>
                </cxf:properties>
        </cxf:bus>
        <util:list id="busProviders">
                <ref bean="jsonProvider"/>
        </util:list>
</beans>

...?

我删除的代码片段仅包含以下一些手动bean定义:

… ?

The snippet I’ve elided is comprised of just a few manual bean definitions like these:

        <bean id="wadlGenerator" class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
                <property name="linkAnyMediaTypeToXmlSchema" value="true"/>
        </bean>

所以我发布的代码片段可能足以开始使用.

So the snippet I posted might be enough to get one started.

这篇关于"org.apache.cxf.jaxrs.bus.providers"不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆