在 OSGi 中加载 XML 配置文件
我想在 OSGi 环境 (FUSE ESB 4.3.1) 中加载捆绑包的配置数据。 Spring DM 提供配置管理的抽象,并允许读取 etc 文件夹中的属性文件。
我想要实现的是加载 XML 文件,因为我需要比简单属性文件更复杂的配置。一个例子可以是:
<measurements>
<measurementsList name="First">
<measurement>First-1</measurement>
<measurement>First-2</measurement>
</measurementsList>
<measurementsList name="Second">
<measurement>Second-1</measurement>
<measurement>Second-2</measurement>
<measurement>Second-3</measurement>
<measurement>Second-4</measurement>
</measurementsList>
...
</measurements>
然后解析它以获取 Map>其中键是测量列表的名称,值是测量名称的列表。
我怎样才能在 OSGi 中做到这一点?我需要将文件放在哪里才能从某个包中访问它?
最好的祝愿, 斯特凡
I would like to load configuration data for a bundle in the OSGi environment (FUSE ESB 4.3.1). Spring DM provides abstraction of the Configuration Admin and allows to read the properties files in etc folder.
What I want to achieve is to load an XML file, since I need a configuration of greater complexity than simple properties file. An example could be:
<measurements>
<measurementsList name="First">
<measurement>First-1</measurement>
<measurement>First-2</measurement>
</measurementsList>
<measurementsList name="Second">
<measurement>Second-1</measurement>
<measurement>Second-2</measurement>
<measurement>Second-3</measurement>
<measurement>Second-4</measurement>
</measurementsList>
...
</measurements>
and then to parse it to get a Map> where the key is the name of measurementsList and value is the list of the measurement names.
How can I do it in OSGi? Where do I need to place my file for it to be accessible from a certain bundle?
Best wishes,
Stefan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将配置保存在单独的 XML 文件中。将文件名或 URL 作为字符串值传递到配置管理员管理的属性中。在可配置对象中,打开文件并读取/处理其中的 XML 内容。
Save the configuration in a separate XML file. Pass the file name or the URL as a string value in a property managed by the Configuration Admin. In the configurable object, open the file and read/process the XML contents there.
我会将 XML 文件放置在 servicemix 下的 etc 文件夹中,并在 spring DM 配置管理中传递相对路径。
相对路径相对于 servicemix 目录起作用
I would place the XML file in etc folder under servicemix, and pass the relative path in the spring DM config admin.
relative path works relative off servicemix directory