3

「Camel in Action」という本を読んでいますが、キャメル ルートで 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 の設定方法を教えてください。OSGiコンテナとして日食分点を使用しています。

4

3 に答える 3

3

camel:runプロジェクトで Spring Camel 構成を使用して、薄い非 OSGi ランタイムを実行するだけです。<osgi:service id="helloService"...>あなたが受け取っているメッセージは、OSGi 環境を見つけることができないSpringDM (をインスタンス化するもの) からのものです。これを機能させるには、Servicemix の Karaf などのサポート コンテナー内にコードをインストールする必要があります。

OSGi が Camel で動作することを確認したい場合は、https://github.com/FuseByExample/smx-bootstrapsで Servicemix Bootstraps プロジェクトを確認してください。コードのインストールと微調整に関する完全なドキュメントがあります。興味のあるバンドルはsmx-pongersmx-ponger-serviceで、それぞれ OSGi サービスの使用と提供を示しています。

于 2012-07-02T11:27:34.093 に答える
1

過去に、ラクダルートに OSGi 依存コンポーネントがあり、Eclipse などの IDE を介して実行/デバッグしたいというこのような状況に遭遇しました。

開発中にデバッグする場合は、ServiceMix にデプロイしてリモートでデバッグできます。

http://servicemix.apache.org/developers/remote-debugging-servicemix-in-eclipse.html

Camel 2.10 は、OSGi 設計図を使用してすぐに使用できるシナリオをサポートする場合があります。

http://camel.apache.org/camel-run-maven-goal.html

于 2012-09-25T03:01:06.677 に答える
0

Spring OSGI 拡張機能は問題ありませんが、ご覧のとおり、同じ Spring コンテキストから Bean を実装して宣言するときにサービス インターフェイスをテストするのは少し近親相姦です。もちろん、Bean が helloBean を参照することもできますが、それでは目的が果たせません。

spring-osgi 拡張機能の動作についてはよくわかりませんが、少なくとも pojosr を使用した非常によく似た camel-blueprint を使用すると、変更された helloService 要素を使用して同じテストを実行できます。

<to uri="bean:camelinaction.testbeans.HelloBean" method="hello" />

Bean id が通常 Bean id を参照している場合、現在は完全修飾インターフェースを使用しているという異常な事実に注意してください。

もちろん、これにはいくつかの残念な制限があります。目的のインターフェイスを実装するサービス インスタンスが 1 つしかない場合は問題なく動作しますが、フィルターを適用する方法について (私には) 明白な方法はありません。その場合の 1 つの代替手段は、CamelContext の bundleContext プロパティを実際に使用し、プログラム API を使用することに頼ることです。しかしもちろん、宣言的なアプローチを支持して、それを避けたいと思います。

于 2014-09-14T13:30:31.913 に答える