我在Apache servicemix中安装了一个使用apache blueprint进行配置的包。我使用的是外部属性文件abc.cfg位于/ config文件夹,并如下加载:通过Java DSL通过蓝图如何通过OSGi blueprint属性占位符和Java DSL加载外部属性文件
<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" />
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,并通过java DSL中的配置管理服务。另外,我不确定是否可以在我的包中以两种不同的方式加载相同的属性文件。
非常感谢你。这工作完美,现在我明白这一点。我摆弄这个太久了,主要是因为缺乏对初学者的良好学习资源。 – ishan
对于初学者和卡拉夫食谱,有一些关于osgi的书籍。这些可能有帮助。不要忘记OSGi在行动。 –