首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Apache Servicemix 4中的OSGi包之间共享配置文件?

在Apache Servicemix 4中的OSGi包之间共享配置文件?
EN

Stack Overflow用户
提问于 2018-09-29 00:40:21
回答 1查看 0关注 0票数 0

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

  1. 有一个文件 $SMX_HOME/etc/myconfiguration.cfg
  2. 使用Spring dm通过OSGi配置管理员将此配置“可用”注入我的软件包,即
代码语言:javascript
复制
<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>
            <prop key =“db.username”> someuser </ prop>
            <prop key =“db.password”> somepassword </ prop>
            <prop key =“amq.brokerURL”> vm:// default </ prop>
        </ osgix:厘米的属性>

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

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

代码语言:javascript
复制
    
    .
    .
    .
        <bean id =“activeMqConnectionFactory”
            类= “org.apache.activemq.ActiveMQConnectionFactory”>
            <property name =“brokerURL”value =“$ {amq.brokerURL}”/>
        </豆>
    .
    .
    .

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

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

EN

回答 1

Stack Overflow用户

发布于 2018-09-29 09:47:51

我分享了我的配置

$SMX_HOME/etc/my.config.cfg

使用此声明

代码语言:javascript
复制
<!-- 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100008888

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档