2

有没有人能够在 SMX4 中的两个或多个捆绑包之间成功共享配置?我正在寻找的是这个:

  1. 有一个文件$SMX_HOME/etc/myconfiguration.cfg
  2. 让这个配置“可用”以通过 OSGi 配置管理使用 Spring dm 注入到我的包中,即
<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 =“我的配置”>
            <prop key="db.driverClassName">org.postgresql.Driver</prop>
            <prop key="db.url">jdbc:postgresql://localhost/db</prop>
            <prop key="db.username">某个用户</prop>
            <prop key="db.password">一些密码</prop>
            <prop key="amq.brokerURL">vm://default</prop>
        </osgix:cm-properties>

        <ctx:property-placeholder properties-ref="cfg" />

然后,我可以将这样的东西注入到我的 bean 中:

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

对于单个捆绑包,所有这些都只是桃子。我正在寻找一种方法来定义它一次,然后能够重用相同的配置文件作为一组包的属性。现在,我有多个包,每个包都有自己的配置实例(持久 id),因此,每个需要数据库连接、Java JMS 等的包都必须在每个文件中重复配置。

目前,我正在使用 Apache Servicemix 4,它使用 Apache Felix 作为 OSGi 容器。

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 的FUSE 4.3 。

于 2010-12-08T10:56:40.453 回答