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

发布于 2024-10-06 14:28:17 字数 2173 浏览 0 评论 0原文

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

  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" />

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

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

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

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

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

  1. Have a single file in $SMX_HOME/etc/myconfiguration.cfg
  2. Have this configuration be "available" to be injected into my bundles via the OSGi Configuration Admin using Spring dm, i.e.
<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>
    .
    .
    .

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千秋岁 2024-10-13 14:28:17

中的配置

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

我使用 FUSE 4.3 它基于 apache-servicemix-4.3.0-fuse-01- 00.

I share my configuration located in

$SMX_HOME/etc/my.config.cfg

using this declaration

<!-- 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" />

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文