如何在 JBoss Fuse Blueprint 中使用多个 属性-placeholder?
How to use multiple property-placeholder in JBoss Fuse Blueprint?
我正在尝试使用 JBoss 中 etc
目录中的 多个 属性 文件 Fuse ( 6.3) 蓝图。我的第一个方法如下:
<cm:property-placeholder persistent-id="foo" />
<cm:property-placeholder persistent-id="bar" />
我认为这可行,正如 Red Hat's documentation:
中所述
Using multiple property placeholders in Blueprint
It is legal to define multiple property placeholders in a Blueprint XML file (that is, defining multiple cm:property-placeholder elements that reference different persistent IDs). One thing that you need to be aware of, however, is that there can be a clash if two properties from different property placeholders have the same name. In this case, the following rules determine which property takes precedence:
Explicitly defined property settings (for example, defined in a etc/PersistentID.cfg
file) take precedence over default property settings (defined in a cm:default-properties
element).
If there is more than one explicit setting for a given property, the setting from the last property placeholder in the Blueprint file takes precedence.
Default property settings (defined in a cm:default-properties
element) have the lowest priority.
但后来我得到了 Multiple placeholders with the same prefix and suffix are not allowed
:
的错误
2018-05-15 17:43:59,065 | ERROR | /s42http1/deploy | BlueprintContainerImpl | 22 - org.apache.aries.blueprint.core - 1.8.0 | Unable to start blueprint container for bundle myBlueprint/0.0.1.SNAPSHOT
org.osgi.service.blueprint.container.ComponentDefinitionException: Multiple placeholders with the same prefix and suffix are not allowed
at org.apache.aries.blueprint.ext.PlaceholdersUtils.validatePlaceholder(PlaceholdersUtils.java:49)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.compendium.cm.CmNamespaceHandler.parsePropertyPlaceholder(CmNamespaceHandler.java:318)[20:org.apache.aries.blueprint.cm:1.1.0]
at org.apache.aries.blueprint.compendium.cm.CmNamespaceHandler.parse(CmNamespaceHandler.java:199)[20:org.apache.aries.blueprint.cm:1.1.0]
at org.apache.aries.blueprint.parser.Parser.parseCustomElement(Parser.java:1369)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.parser.Parser.loadComponents(Parser.java:427)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.parser.Parser.populate(Parser.java:331)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:350)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:277)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:300)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:269)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:265)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:255)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1127)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2100)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316)[10:org.apache.felix.fileinstall:3.6.4]
所以我设置了 placeholder-prefix
和 placeholder-suffix
:
<cm:property-placeholder persistent-id="foo" />
<cm:property-placeholder persistent-id="bar"
placeholder-prefix="$(" placeholder-suffix=")"/>
有了它,我应该可以使用 ${ } 访问 etc/foo.cfg
和使用 $ ( ) 访问 etc/bar.cfg
属性,对吗?
否:
Caused by: java.io.IOException: Could not open $(bar_property) as a file, class path resource, or URL.
at org.apache.camel.util.jsse.JsseParameters.resolveResource(JsseParameters.java:182)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.util.jsse.KeyStoreParameters.createKeyStore(KeyStoreParameters.java:174)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.util.jsse.KeyManagersParameters.createKeyManagers(KeyManagersParameters.java:108)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.util.jsse.SSLContextParameters.createSSLContext(SSLContextParameters.java:256)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.component.http4.HttpComponent.createConnectionRegistry(HttpComponent.java:285)[296:org.apache.camel.camel-http4:2.17.0.redhat-630329]
at org.apache.camel.component.http4.HttpComponent.createEndpoint(HttpComponent.java:227)[296:org.apache.camel.camel-http4:2.17.0.redhat-630329]
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:114)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:569)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
... 36 more
而且我已经检查 bar_property
存在于 etc/bar.cfg
中。
那么如何在 JBoss Fuse 蓝图中使用多个 属性 占位符?我正在使用 JBoss 保险丝 6.3.0.329.
当我输入那个问题时,我在 RedHat documentation (Rubber duck debugging 引用部分的正上方找到了答案 ;-) :
The syntax, {{prefix}}
, substitutes the value of the prefix
variable into the blueprint XML file. The OSGi properties are set up using the following XML elements:
cm:property-placeholder
This element gives you access to the properties associated with the specified persistent ID. After defining this element, you can use the syntax, {{PropName}}
, to substitute variables belonging to the specified persistent ID.
cm:property-placeholder/cm:default-properties
You can optionally specify default values for properties by defining cm:property
elements inside the cm:default-properties
element. If the corresponding etc/PersistentID.cfg
file defines property values, however, these will be used instead.
所以 属性 占位符的定义是正确的,如下所示:
<cm:property-placeholder persistent-id="foo" />
<cm:property-placeholder persistent-id="bar"
placeholder-prefix="$(" placeholder-suffix=")"/>
但在我的示例中,属性 必须与 {{bar_property}}
一起使用,而不是 $(bar_property)
。
我正在尝试使用 JBoss 中 etc
目录中的 多个 属性 文件 Fuse ( 6.3) 蓝图。我的第一个方法如下:
<cm:property-placeholder persistent-id="foo" />
<cm:property-placeholder persistent-id="bar" />
我认为这可行,正如 Red Hat's documentation:
中所述Using multiple property placeholders in Blueprint
It is legal to define multiple property placeholders in a Blueprint XML file (that is, defining multiple cm:property-placeholder elements that reference different persistent IDs). One thing that you need to be aware of, however, is that there can be a clash if two properties from different property placeholders have the same name. In this case, the following rules determine which property takes precedence:
Explicitly defined property settings (for example, defined in a
etc/PersistentID.cfg
file) take precedence over default property settings (defined in acm:default-properties
element).If there is more than one explicit setting for a given property, the setting from the last property placeholder in the Blueprint file takes precedence.
Default property settings (defined in a
cm:default-properties
element) have the lowest priority.
但后来我得到了 Multiple placeholders with the same prefix and suffix are not allowed
:
2018-05-15 17:43:59,065 | ERROR | /s42http1/deploy | BlueprintContainerImpl | 22 - org.apache.aries.blueprint.core - 1.8.0 | Unable to start blueprint container for bundle myBlueprint/0.0.1.SNAPSHOT
org.osgi.service.blueprint.container.ComponentDefinitionException: Multiple placeholders with the same prefix and suffix are not allowed
at org.apache.aries.blueprint.ext.PlaceholdersUtils.validatePlaceholder(PlaceholdersUtils.java:49)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.compendium.cm.CmNamespaceHandler.parsePropertyPlaceholder(CmNamespaceHandler.java:318)[20:org.apache.aries.blueprint.cm:1.1.0]
at org.apache.aries.blueprint.compendium.cm.CmNamespaceHandler.parse(CmNamespaceHandler.java:199)[20:org.apache.aries.blueprint.cm:1.1.0]
at org.apache.aries.blueprint.parser.Parser.parseCustomElement(Parser.java:1369)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.parser.Parser.loadComponents(Parser.java:427)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.parser.Parser.populate(Parser.java:331)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:350)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:277)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:300)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:269)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:265)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:255)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1127)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2100)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316)[10:org.apache.felix.fileinstall:3.6.4]
所以我设置了 placeholder-prefix
和 placeholder-suffix
:
<cm:property-placeholder persistent-id="foo" />
<cm:property-placeholder persistent-id="bar"
placeholder-prefix="$(" placeholder-suffix=")"/>
有了它,我应该可以使用 ${ } 访问 etc/foo.cfg
和使用 $ ( ) 访问 etc/bar.cfg
属性,对吗?
否:
Caused by: java.io.IOException: Could not open $(bar_property) as a file, class path resource, or URL.
at org.apache.camel.util.jsse.JsseParameters.resolveResource(JsseParameters.java:182)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.util.jsse.KeyStoreParameters.createKeyStore(KeyStoreParameters.java:174)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.util.jsse.KeyManagersParameters.createKeyManagers(KeyManagersParameters.java:108)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.util.jsse.SSLContextParameters.createSSLContext(SSLContextParameters.java:256)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.component.http4.HttpComponent.createConnectionRegistry(HttpComponent.java:285)[296:org.apache.camel.camel-http4:2.17.0.redhat-630329]
at org.apache.camel.component.http4.HttpComponent.createEndpoint(HttpComponent.java:227)[296:org.apache.camel.camel-http4:2.17.0.redhat-630329]
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:114)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:569)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
... 36 more
而且我已经检查 bar_property
存在于 etc/bar.cfg
中。
那么如何在 JBoss Fuse 蓝图中使用多个 属性 占位符?我正在使用 JBoss 保险丝 6.3.0.329.
当我输入那个问题时,我在 RedHat documentation (Rubber duck debugging 引用部分的正上方找到了答案 ;-) :
The syntax,
{{prefix}}
, substitutes the value of theprefix
variable into the blueprint XML file. The OSGi properties are set up using the following XML elements:
cm:property-placeholder
This element gives you access to the properties associated with the specified persistent ID. After defining this element, you can use the syntax,{{PropName}}
, to substitute variables belonging to the specified persistent ID.
cm:property-placeholder/cm:default-properties
You can optionally specify default values for properties by definingcm:property
elements inside thecm:default-properties
element. If the correspondingetc/PersistentID.cfg
file defines property values, however, these will be used instead.
所以 属性 占位符的定义是正确的,如下所示:
<cm:property-placeholder persistent-id="foo" />
<cm:property-placeholder persistent-id="bar"
placeholder-prefix="$(" placeholder-suffix=")"/>
但在我的示例中,属性 必须与 {{bar_property}}
一起使用,而不是 $(bar_property)
。