在 Apache Servicemix 4 中的 OSGi 包之间共享配置文件?
有人能够在 SMX4 中的两个或多个捆绑包之间成功共享配置吗?我正在寻找的是这样的:
- 在
$SMX_HOME/etc/myconfiguration.cfg
中有一个文件 - 让此配置“可用”,以便使用 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:
- Have a single file in
$SMX_HOME/etc/myconfiguration.cfg
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
中的配置
共享位于
$SMX_HOME/etc/my.config.cfg
使用此声明来
我在每个包中 。看起来与您的解决方案非常相似并且工作完美!
您可以共享您的配置(不需要为每个包提供配置文件),但您必须在每个 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
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.