【问题标题】:Multiple CXF bundles in OSGI binding to same addressOSGI 中的多个 CXF 捆绑包绑定到同一地址
【发布时间】:2018-09-04 14:53:07
【问题描述】:

我有多个暴露 CXF JAXRS 端点的 WAR。他们有相似的 web.xml

<web-app id="app1">
    <context-param>
        <param-name>contextClass</param-name>
        <param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
    </context-param>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:META-INF/spring/*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>app1</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>app1</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

它们共享共同的 Spring 配置(命名为 common-rest.xml

<beans>
    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <context:annotation-config />  

    <bean id="httpDestinationRegistry"
    class="org.apache.cxf.transport.http.DestinationRegistryImpl" />

    <bean id="baseJaxRSServer"
        abstract="true"
        lazy-init="false"
        class="org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser.SpringJAXRSServerFactoryBean"
        init-method="create"
        p:address="${http.server}/" />
</beans>

每个bean都有相似的配置

<beans>
    <import resource="classpath:META-INF/app/common-rest.xml" />

    <bean id="app1JaxRSServer"
        parent="baseJaxRSServer"
        p:serviceBeans-ref="app1ServiceBeans" />
</beans>

确切的路径在每个包的清单中定义

Web-ContextPath: app1

问题是我不能让多个捆绑包一起工作。使用单个捆绑包可以正常工作,但是如果我尝试运行另一个捆绑包,则创建 app1JaxRSServer bean 时会出现异常

org.apache.cxf.service.factory.ServiceConstructionException: There is an endpoint already running on /.

使用 Karaf 4.0.9、CXF 3.1.13、Spring 3.2.18

【问题讨论】:

    标签: spring osgi cxf apache-karaf karaf


    【解决方案1】:

    原因是

     <url-pattern>/*</url-pattern> 
    

    如果您有多个具有此设置的捆绑包,它们的端点将发生冲突。

    尝试为每个包使用不同的前缀。

    【讨论】:

    • 它没有帮助。我发布的配置适用于 Karaf 3 和 CXF 2.6。现在我升级了版本并遇到了这个错误
    • 其实你是对的,Web-Contextpath 应该已经提供了一个前缀。让我们看看是否有人有更好的主意。如果没有,你应该在 CXF 上打开一个问题。
    【解决方案2】:

    我找到了解决方案,DestionationRegistry 存在问题,它是由 CXF HTTP Transport OSGI Bundle(注册默认 /cxf/* 端点的那个)默认创建的。我不得不通过设置禁用这个捆绑包

    org.apache.cxf.osgi.http.transport.disable = true

    在卡拉夫属性中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-18
      • 2014-03-02
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      • 1970-01-01
      • 2020-09-13
      • 2016-12-05
      相关资源
      最近更新 更多