有没有人能够在SMX4中成功共享两个或更多捆绑包之间的配置?我正在寻找的是:
$SMX_HOME/etc/myconfiguration.cfg
<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:
.
.
.
<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容器。
发布于 2018-09-29 09:47:51
我分享了我的配置
$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。
https://stackoverflow.com/questions/-100008888
复制相似问题