2

SMX4の2つ以上のバンドル間で構成を正常に共有できた人はいますか?私が探しているのはこれです:

  1. に単一のファイルがある$SMX_HOME/etc/myconfiguration.cfg
  2. この構成を「利用可能」にして、Springdmを使用するOSGi構成管理者を介してバンドルに注入できるようにします。
<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"
        xmlns:osgix = "http://www.springframework.org/schema/osgi-compendium"
        xmlns:ctx = "http://www.springframework.org/schema/context"
        xsi:schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                            http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd
                            http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium-1.2.xsd">

        <osgix:cm-properties id = "cfg"
            永続的-id="myconfiguration">
            <prop key = "db.driverClassName"> org.postgresql.Driver </ prop>
            <prop key = "db.url"> jdbc:postgresql:// localhost / db </ prop>
            <propkey="db.username">一部のユーザー</prop>
            <prop key = "db.password"> somepassword </ prop>
            <prop key = "amq.brokerURL"> vm:// default </ prop>
        </ osgix:cm-properties>

        <ctx:property-placeholderproperties-ref = "cfg" />

次に、次のようなものをBeanに注入できます。

    
    。
    。
    。
        <bean id = "activeMqConnectionFactory"
            class = "org.apache.activemq.ActiveMQConnectionFactory">
            <property name = "brokerURL" value = "$ {amq.brokerURL}" />
        </ bean>
    。
    。
    。

単一のバンドルの場合、それはすべて桃色です。私が探しているのは、これを一度定義してから、バンドルのセットのプロパティと同じ構成ファイルを再利用できるようにする方法です。現在、複数のバンドルがあり、それぞれに独自の構成インスタンス(永続ID)があるため、データベース接続やJava JMSなどを必要とする各バンドルでは、すべてのファイルで構成を繰り返す必要があります。

現在、OSGiコンテナーとしてApacheFelixを使用しているApacheServicemix4を使用しています。

4

1 に答える 1

3

にある構成を共有します

$SMX_HOME/etc/my.config.cfg

この宣言を使用する

<!-- get properties as bean from OSGi Configuration Admin Service -->
<osgix:cm-properties id="myConfig" persistent-id="my.config" />

<!-- activate ${...} placeholder -->
<ctx:property-placeholder properties-ref="myConfig" />

私のバンドルのそれぞれで。あなたのソリューションに非常によく似ており、完璧に機能します!構成を共有できますが(バンドルごとに構成ファイルを提供する必要はありません)、各spring-application-contextファイルでこの構成への参照を宣言する必要があります。

apache-servicemix-4.3.0-fuse- 01-00に基づくFUSE4.3を使用しています。

于 2010-12-08T10:56:40.453 に答える