简体   繁体   English

如何从BlueBoots XML的XML属性文件中读取值?

[英]How do I read values from property file in Blueprint XML for JBoss Fuse?

How can I read values from the property file in Blueprint XML for JBoss Fuse? 如何从BlueBoots XML的XML的属性文件中读取值?

Currently, I am reading like below, but I want to read from a property file. 目前,我正在阅读以下内容,但是我想从属性文件中阅读。 Can I use Spring BridgePropertyPlaceholoder to achieve it? 我可以使用Spring BridgePropertyPlaceholoder实现它吗?

<cm:property-placeholder persistent-id="connections" update-
strategy="reload">
<cm:default-properties>
<cm:property name="xyz" value="http://xx.xx.x.x:x0x0/xxx/yyy"/>
<cm:property name="pqr" value="http://xx.xx.x.x:x0x0/xxx/yyy"/>
<cm:property name="lmn" value="mnopqr"/>
</cm:default-properties>
</cm:property-placeholder>

Actually, blueprint-ext and blueprint-cm that extends from it, support an external source for properties file, unrelated to the defualt ConfigAdmin used location. 实际上,从其扩展的blueprint-extblueprint-cm支持属性文件的外部源,该源与默认ConfigAdmin使用位置无关。

It allows you to write something like: 它允许您编写如下内容:

``` ```

  <cm:property-placeholder persistent-id="mytest"  update-strategy="reload">
<cm:location>file:///whatever/my.properties</ext:location>
  </cm:property-placeholder>

``` ```

Se reference in blueprint-cm xsd here: se在blueprint-cm xsd中的引用在这里:

http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.3.0.xsd http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.3.0.xsd

Your are already doing it the right way. 您已经在以正确的方式这样做。

persistent-id indicates the name of a file in the etc/ folder of JBoss Fuse. persistent-id表示JBoss Fuse的etc/文件夹中的文件名。 In your case, it is etc/connections.cfg . 您的情况是etc/connections.cfg You also have autoreload if someone edits the file. 如果有人编辑文件,您还将具有自动重新加载的功能。

Be aware that cfg files are property files. 请注意,cfg文件属性文件。 From: https://docs.oracle.com/javase/tutorial/essential/environment/properties.html 来自: https : //docs.oracle.com/javase/tutorial/essential/environment/properties.html

Properties 属性
Properties are configuration values managed as key/value pairs . 属性是作为键/值对管理的配置值。 In each pair, the key and value are both String values. 在每对中,键和值都是String值。 The key identifies, and is used to retrieve, the value, much as a variable name is used to retrieve the variable's value. 键标识并用于检索值,就像变量名用于检索变量的值一样。

Some other specs if you want to be 100% sure: http://kajabity.com/kajabity-tools/java-properties-classes/the-java-properties-file-format/ 如果您想100%确定某些其他规格,请访问: http : //kajabity.com/kajabity-tools/java-properties-classes/the-java-properties-file-format/

So you are already reading a property file. 因此,您已经在读取属性文件。 Just with a different extension. 只是具有不同的扩展名。

NOTE : 注意
If you meant you want to read files scattered around the file system to configure your bundles, I strongly advise you not to do it , you're looking for troubles. 如果您想读取分散在文件系统中的文件以配置捆绑软件,我强烈建议您不要这样做 ,这是在寻找麻烦。 Do this only if you know what you are doing and you have a reason to do it . 仅当您知道自己在做什么并且有理由这样做时,才执行此操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM