2016-11-08 101 views
1

我只能在這裏使用字符串綁定,enableRequestValidation應該總是字符串,放在我的bean我想要使用布爾值,我怎樣才能實現這個使用屬性佔位符綁定?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

你能夠使用白羊座藍圖配置管理?您不提供有關您的環境的任何信息,但使用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(布爾設置)方法並嘗試將該字符串轉換爲布爾值。這裏指定了默認值「true」,但可以通過對etc/myProps.cfg的更改覆蓋。