0

Spring DM を学習していますが、サービス レジストリに問題があります。Felix インスタンスが埋め込まれた ServiceMix 4.3.0 を使用しています。私のプロジェクトには 2 つのバンドルがあります。

最初のものには、インターフェースとモック実装が含まれています。それらを OSGi サービス レジストリに公開したい:

public interface PersonAPI {
    public void listAll();
    public List<PersonEntity> getAll();
    public void addPerson(PersonEntity pe);
    public PersonEntity getPerson(int id);
}

PersonEntity はデータを持つ単純なクラスであり、特別なことは何もありません。

モック実装には PeopleEntity オブジェクトのリストだけが含まれているため、興味深いものは何もありません。

以下は Spring 構成 XML の一部です。

<bean id="personImpl" class="com.osgi.Person.impl.mock.PersonImpl" />
<osgi:service id="personLogic" ref="personImpl" interface="com.osgi.Person.PersonAPI" />

pom.xml ファイルから抜粋した部分:

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.4</version>
<extensions>true</extensions>
<configuration>
    <instructions>
        <Bundle-Category>sample</Bundle-Category>
        <Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
        <Export-package>com.osgi.*</Export-package>
    </instructions>
</configuration>
</plugin>

これは ServiceMix に問題なくインストールされます。ここで、別のバンドルを定義しました。最も重要な部分は次のとおりです。

public class PersonTester {
    PersonAPI api;

public void init() {
    System.out.println("PostConstruct:");
    System.out.println("Have API " + api + " class " + api.getClass().getCanonicalName());

    api.listAll(); //This line (or any API call, blows everything)
}

public PersonAPI getApi() {
    return api;
}

public void setApi(PersonAPI api) {
    this.api = api;
}
}

春の構成:

<osgi:reference id="personLogic" interface="com.osgi.Person.PersonAPI" />   
<bean id="personTester" init-method="init" class="com.osgi.Person.PersonTester">
    <property name="api" ref="personLogic" />       
</bean>

pom.xml の最も重要な部分:

<dependencies>
    <dependency>
        <groupId>com.osgi</groupId>
        <artifactId>Pserson-API</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
....

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.4</version>
<extensions>true</extensions>
<configuration>
    <instructions>
        <Bundle-Category>sample</Bundle-Category>
        <Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
        <Import-package>com.Person.entity,com.osgi.Person</Import-package>
    </instructions>
</configuration>
</plugin>

良いニュースは、注入された Spring プロキシの「背後」が私の実装クラスであることです。api.toString() を使用するとわかります。ただし、プロキシで定義されたメソッドを呼び出すと、例外が発生します。

スレッド「SpringOsgiExtenderThread-88」での例外 org.springframework.beans.factory.BeanCreationException: 名前 'personTester' の Bean の作成中にエラーが発生しました: init メソッドの呼び出しに失敗しました。ネストされた例外は org.springframework.aop.AopInvocationException: AOP 構成が無効のようです: メソッド [public abstract void com.osgi.Person.PersonAPI.listAll()] をターゲット [PersonImpl [set=[]]] で呼び出してみました。ネストされた例外は java.lang.IllegalArgumentException です: オブジェクトは宣言クラスのインスタンスではありません

AOP がターゲットを逃しているように見えますが、なぜですか? そして、これを修正する方法は?

4

1 に答える 1

0

問題は修正されました。それは環境の中にあるものでした。

このチュートリアルの上に(異なるアーティファクトIDを使用して)新しいプロジェクトの構築を開始しましたが、すべて問題ないようです。おそらくどこかにキャッシュされたものがあります(ServiceMixバンドルキャッシュとローカルMavenリポジトリをフラッシュしたため奇妙です)。別のマシンで再現しようとしていますが、もっと良い説明が出てくるかもしれません。

于 2011-05-26T09:31:49.927 に答える