gpt4 book ai didi

spring - 在 Camel route 使用 OSGi 服务

转载 作者:行者123 更新时间:2023-12-01 14:05:40 25 4
gpt4 key购买 nike

我正在阅读“Camel in Action”一书,但我无法计算出在 camel 路由中使用 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 运行时。您收到的消息来自无法找到 OSGi 环境的 SpringDM(实例化 <osgi:service id="helloService"...> 的东西)。要使其正常工作,您需要将代码安装在支持容器中 - 例如 Servicemix 的 Karaf。

如果您希望看到 OSGi 与 Camel 一起工作,请查看位于 https://github.com/FuseByExample/smx-bootstraps 的 Servicemix Bootstraps 项目。 - 关于安装和调整代码的完整文档。您会感兴趣的 bundle 有 smx-pongersmx-ponger-service ,分别展示了OSGi服务的消费和提供。

关于spring - 在 Camel route 使用 OSGi 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10898627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com