春季-在骆驼路线中使用OSGi服务
作者:互联网
我正在读《行动中的骆驼》这本书,但我无法得出在骆驼路线中使用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