标签:osgi maven-2 apache-camel spring
我正在读《行动中的骆驼》这本书,但我无法得出在骆驼路线中使用OSGi服务的示例(第4.3.4节OsgiServiceRegistry).这是我的bean(作为OSGi服务公开
public class HelloBean {
public String hello(String name){
System.out.println(" Invoking Hello method ");
return "Hello " + name;
}
}
这是将上述bean作为服务公开的spring XML文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<bean id="helloBean" class="camelinaction.testbeans.HelloBean" />
<osgi:service id="helloService" interface="camelinaction.testbeans.HelloBean" ref="helloBean" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<bean ref="helloService" method="hello" />
</route>
</camelContext>
</beans>
当我执行Maven目标’camel:run’时,出现以下异常:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloService': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: required property 'bundleContext' has not been set
请让我知道如何设置bundleContext.我正在使用Eclipse Equinox作为OSGi容器.
解决方法:
camel:run仅使用项目中的Spring Camel配置运行非OSGi精简运行时.您收到的消息来自SpringDM(实例化< osgi:service id =“ helloService” ...>的消息)无法找到OSGi环境.为了使其正常工作,您需要将代码安装在支持容器中,例如Servicemix的Karaf.
如果您希望OSGi与Camel一起使用,请查看位于https://github.com/FuseByExample/smx-bootstraps的Servicemix Bootstraps项目-有关安装和调整代码的完整文档.您将感兴趣的捆绑软件包括smx-ponger和smx-ponger-service,它们分别演示了OSGi服务的使用和提供.
标签:osgi,maven-2,apache-camel,spring 来源: https://codeday.me/bug/20191101/1982191.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。