我试图运行一个独立的OSGi框架来运行其中执行驼峰路由的蓝图捆绑包。 OSGi框架是Apache Felix,蓝图实现是Apache Aries。
以下捆绑包加载到框架的BundleContext
:
现在我有一个测试包,其蓝图定义包含camelContext
,如下所示:
<?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 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route id="testRoute1">
<from uri="timer:foo?period=5000" />
<log message="Hello world!" />
</route>
</camelContext>
</blueprint>
即使加载了所有捆绑包并解决了需求,蓝图容器也会提供以下日志:
[de.hff.yosgi.test1.Test] : Installing test bundle
[org.apache.aries.blueprint.container.BlueprintExtender] : Starting BlueprintContainer destruction process for bundle osgi-test1
[org.apache.aries.blueprint.container.BlueprintExtender] : Not a blueprint bundle or destruction of BlueprintContainer already finished for osgi-test1.
[org.apache.aries.blueprint.container.BlueprintExtender] : Starting BlueprintContainer destruction process for bundle osgi-test1
[org.apache.aries.blueprint.container.BlueprintExtender] : Not a blueprint bundle or destruction of BlueprintContainer already finished for osgi-test1.
[de.hff.yosgi.test1.Test] : Test bundle installed, starting
[org.apache.aries.blueprint.container.BlueprintExtender] : Starting BlueprintContainer destruction process for bundle osgi-test1
[org.apache.aries.blueprint.container.BlueprintExtender] : Not a blueprint bundle or destruction of BlueprintContainer already finished for osgi-test1.
[org.apache.aries.blueprint.container.BlueprintExtender] : Starting BlueprintContainer destruction process for bundle osgi-test1
[org.apache.aries.blueprint.container.BlueprintExtender] : Not a blueprint bundle or destruction of BlueprintContainer already finished for osgi-test1.
[org.apache.aries.blueprint.container.BlueprintExtender] : Scanning bundle osgi-test1 for blueprint application
[org.apache.aries.blueprint.container.BlueprintExtender] : Found blueprint application in bundle osgi-test1 with paths: [bundle://24.0:0/OSGI-INF/blueprint/blueprint.xml]
[org.apache.aries.blueprint.container.BlueprintExtender] : Scheduling creation of blueprint bundle osgi-test1 asynchronously
[org.apache.aries.blueprint.container.BlueprintContainerImpl] : Running blueprint container for bundle osgi-test1 in state Unknown
[org.apache.aries.blueprint.container.BlueprintEventDispatcher] : Sending blueprint container event BlueprintEvent[type=CREATING] for bundle osgi-test1
[de.hff.yosgi.test1.Test] : Test bundle started
[org.apache.aries.blueprint.container.BlueprintContainerImpl] : Running blueprint container for bundle osgi-test1 in state WaitForNamespaceHandlers
[org.apache.aries.blueprint.container.BlueprintContainerImpl] : Bundle osgi-test1 is waiting for namespace handlers [http://camel.apache.org/schema/blueprint]
[org.apache.aries.blueprint.container.BlueprintEventDispatcher] : Sending blueprint container event BlueprintEvent[type=GRACE_PERIOD, dependencies=[(&(objectClass=org.apache.aries.blueprint.NamespaceHandler)(osgi.service.blueprint.namespace=http://camel.apache.org/schema/blueprint))]] for bundle osgi-test1
这里重要的一行是Waiting for namespace handlers
:测试包无法找到camel-blueprint命名空间。但是这个命名空间应该在已安装的camel-blueprint包中定义。
如果没有蓝图中的camelContext
,一切正常(蓝图服务已加载并初始化)。
有没有人遇到类似的问题?什么阻止测试包访问camel-blueprint提供的命名空间?
答案 0 :(得分:0)
我们通过清理依赖项来解决此问题。实际上只需要以下内容:
此外,要成功使Camel在Aries Blueprint中运行,在实例化框架时还需要一个额外的参数。这允许捆绑包访问sun.*
包。
Iterator<FrameworkFactory> iterator =
ServiceLoader.load(FrameworkFactory.class).iterator();
FrameworkFactory factory = iterator.next();
Map<> configuration = new HashMap<String, String>();
configuration.put("org.osgi.framework.bootdelegation", "sun.*");
this.framework = factory.newFramework(configuration);