我在Apache servicemix中安装了一个包,它使用apache blueprint进行配置。我使用的是位于/config文件夹中的外部属性文件abc.cfg,加载方式如下:
通过蓝图
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/blueprint/core"
xsi:schemaLocation="
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0">
<cm:property-placeholder id="myProperties" persistent-id="abc" />通过java DSL
public class MyActivator implements BundleActivator {
@Override
public void start(final BundleContext context) throws Exception {
final ServiceReference serviceReference = context.getServiceReference(ConfigurationAdmin.class.getName());
if (serviceReference != null) {
final ConfigurationAdmin admin = (ConfigurationAdmin) context.getService(serviceReference);
final Configuration configuration = admin.getConfiguration("abc");
final Dictionary<String, Object> configurations = configuration.getProperties();
if (configurations == null) {
throw new CustomException("Exception in loading properties file");
}
populateProperties(configurations);
}
}
}一切正常,但现在我需要将属性文件移动到自定义位置,以便将属性文件从不同的包中分离出来。因此,我将abc.cfg移到了/config/myFolder/中,但我无法以任何一种方式将新位置指定到我的包中。我试过使用ext:property-placeholder,但它不起作用,可能是因为我用错了(找不到任何全面的东西来理解它)。因此,请指导我如何在cm:property-placeholder中指定我属性文件的位置,并通过java DSL中的配置管理服务。此外,我不确定是否可以在我的包中以两种不同的方式加载相同的属性文件。
https://stackoverflow.com/questions/30474886
复制相似问题