【发布时间】:2017-03-09 08:26:37
【问题描述】:
我正在尝试创建两个基于 Camel servlet 的 API(两个 OSGi 包)。我正在使用 this example 中的蓝图 XML。
这是两个蓝图 XML,
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<reference id="httpService" interface="org.osgi.service.http.HttpService"/>
<bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer"
init-method="register"
destroy-method="unregister">
<property name="alias" value="/digital"/>
<property name="httpService" ref="httpService"/>
<property name="servlet" ref="teamCamelServlet"/>
</bean>
<bean id="teamCamelServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/>
<bean id="teamService" class="com.test.TeamService"/>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<restConfiguration component="servlet" bindingMode="json" contextPath="/digital"
port="8181">
<dataFormatProperty key="prettyPrint" value="true"/>
</restConfiguration>
<rest path="/team" consumes="application/json" produces="application/json">
..content omitted
</rest>
</camelContext>
</blueprint>
其他blueprint.xml:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<reference id="httpService" interface="org.osgi.service.http.HttpService"/>
<bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer"
init-method="register"
destroy-method="unregister">
<property name="alias" value="/api"/>
<property name="httpService" ref="httpService"/>
<property name="servlet" ref="camelServlet"/>
</bean>
<bean id="camelServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/>
<bean id="helloService" class="com.test.HelloService"/>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<restConfiguration component="servlet" bindingMode="json" contextPath="/api"
port="8181">
<dataFormatProperty key="prettyPrint" value="true"/>
</restConfiguration>
<!-- defines the rest services using the context-path /user -->
<rest path="/hello" consumes="application/json" produces="application/json">
..content omitted
</rest>
</camelContext>
</blueprint>
但我收到此错误消息:
javax.servlet.ServletException: Duplicate ServletName detected: CamelServlet. Existing: CamelHttpTransportServlet[name=CamelServlet] This: CamelHttpTransportServlet[name=CamelServlet]. Its advised to use unique ServletName per Camel application.
我在这里做错了什么?我正在尝试在 Apache ServiceMix 中运行这两个 OSGi 包。如果其中一个部署,那么它工作正常。如果两者都部署,则只有第一个在工作。我是 Apache Camel 的新手,任何帮助都会很棒。我试过重新启动 ServiceMix,但没有运气。还尝试了清除捆绑缓存。
【问题讨论】:
-
你可以为两个包添加完整的 blueprint.xml 吗?
-
我认为您可能已经在两个 servlet 定义中声明了端口。最好使用 pax web servlet(在 cxfservlet 上您只需删除端口,但我不确定如何使用其余配置组件执行此操作)
-
@stringy05 谢谢,我会调查的。顺便说一句,它没有抱怨任何端口绑定问题。
-
不,它从不这样做(对于我使用过的版本),其他 servlet 组件发生的情况是它尝试绑定,如果成功则记录它,然后如果第二次绑定失败则不记录任何内容。如果您将第二个端口更改为 8182,这样可以吗?
标签: java apache-camel apache-karaf apache-servicemix