在Apache Servicemix 4中的OSGi包之间共享配置文件? [英] Sharing a configuration file between OSGi bundles in Apache Servicemix 4?

查看:169
本文介绍了在Apache Servicemix 4中的OSGi包之间共享配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Has anyone been able to successfully share configuration between two or more bundles in SMX4? What I'm looking for is this:


  1. $ SMX_HOME / etc / myconfiguration.cfg中有一个文件

  2. 使用Spring dm通过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"
            persistent-id="myconfiguration">
            <prop key="db.driverClassName">org.postgresql.Driver</prop>
            <prop key="db.url">jdbc:postgresql://localhost/db</prop>
            <prop key="db.username">someuser</prop>
            <prop key="db.password">somepassword</prop>
            <prop key="amq.brokerURL">vm://default</prop>
        </osgix:cm-properties>

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

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

Then, I can inject things like this into my bean(s):

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

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

All of that is just peachy, for a single bundle. What I am looking for is a way to define this once and then be able to reuse the same configuration file as properties for a set of bundles. Right now, I have multiple bundles, each with their own configuration instance (persistent id) and thus, each bundle that needs a database connection, Java JMS, etc. has to have the configuration repeated in every file.

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

Currently, I'm using Apache Servicemix 4, which is using Apache Felix as the OSGi container.

推荐答案

我分享我的配置

$ 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文件中声明对此配置的引用。

in each of my bundles. Looks quite similar to your solution and works perfect! You can share your configuration (do not need to provide a configuration file for each bundle) but you have to declare the reference to this configuration in each spring-application-context file.

我正在使用基于apache-servicemix-4.3的 FUSE 4.3 。 0-fuse-01-00。

Im using FUSE 4.3 which is based on apache-servicemix-4.3.0-fuse-01-00.

这篇关于在Apache Servicemix 4中的OSGi包之间共享配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆