2016-11-08 8 views
1

ここでは文字列バインディングしか使用できませんが、enableRequestValidationは常に文字列でなければなりません。私のbeanに入れてください。booleanを使用したいのですが、プロパティプレースホルダバインディングを使用してこれを実現できますか?Osgiプロパティプレースホルダー

<property-placeholder 
    persistent-id="JsonValidator" 
    update-strategy="reload" placeholder-prefix="$[" placeholder-suffix="]"> 
    <default-properties> 
     <property name="enableRequestValidation" value="false"></property> 
    </default-properties> 
</property-placeholder> 

<bean id="jsonSchemaRegistration"  class="rest.service.impl.jsonschema.JsonSchemaDynamicFeatureImpl"> 
    <property name="enableRequestValidation" value="$[enabledRequestValidation]"></property> 
</bean> 

追加例外は青写真は、プロパティのプレースホルダをサポートしていません

2016-11-08 11:25:34,944 | ERROR | Thread-74  | BlueprintContainerImpl 
     | 15 - org.apache.aries.blueprint.core - 1.4.4 | Unable to start blueprint 
container for bundle core.rest.service.impl/0.6.0.SNAP 
SHOT 
org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting 
property: PropertyDescriptor <name: enableRequestValidation, getter: class core.rest.service.impl.jsonschema.JsonSchemaDynamicFeatureI 
mpl.isEnableRequestValidation(), setter: [class JsonSchemaDynamicFeatureImpl.setEnableRequestValidati 
on(boolean)] 
     at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecip 
e.java:939)[15:org.apache.aries.blueprint.core:1.4.4] 
     at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRec 
ipe.java:905)[15:org.apache.aries.blueprint.core:1.4.4] 
     at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRec 
ipe.java:886)[15:org.apache.aries.blueprint.core:1.4.4] 
+0

どのようなエラーが発生しますか?私は青写真が値を自動的に変換するので、これがうまくいくと思います。 –

+0

質問にスタックトレースを追加しました –

答えて

-1

以下のようなものです。

+0

downvoteがなぜわからないのですか? Blueprintの仕様には、私が述べたようにプロパティのプレースホルダのサポートは含まれていません。 –

1

Aries Blueprint Configuration Managagementを使用できますか?あなたの環境についての情報は提供しませんが、ServiceMixを使用すると、私はこれを常に行います。例:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:config="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" 
    xsi:schemaLocation=" 
    http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/smlns/blueprint/v1.0.0/blueprint.xsd"> 

    <!-- OSGi blueprint property placeholder binding to a configuration file --> 
    <config:property-placeholder id="myProps.props" persistent-id="myProps" update-strategy="reload"> 
    <config:default-properties> 
     <config:property name="my.setting" value="true" /> 
    </config:default-properties> 
    </config:property-placeholder> 

    <bean id="myBean" class="org.me.MyClass"> 
    <property name="setting" value="${my.setting}" /> 
    </bean> 
</blueprint> 

更新戦略設定をサポートするblueprint-cm名前空間のバージョン1.1.0が含まれていることに注意してください。プロパティインジェクションは、setSetting(boolean setting)メソッドを見つけ、その文字列をブール値に変換しようとします。ここでは、 "true"のデフォルト値が指定されていますが、これはetc/myProps.cfgの変更で上書きできます。