Osgi财产占位符 [英] Osgi Property Placeholder

查看:113
本文介绍了Osgi财产占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只能在这里使用字符串绑定,enableRequestValidation应该始终是字符串,将其放入我想使用布尔值的bean中,如何使用属性占位符绑定来实现此目的?

I can only use string binding here, enableRequestValidation should be always string, put in my bean i want to use boolean, how can i achieve this using property-placeholder bindings?

<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]

推荐答案

您可以使用Aries Blueprint配置管理吗?您没有提供有关您的环境是什么的任何信息,但是我一直使用ServiceMix进行此操作.例如:

Are you able to use Aries Blueprint Configuration Managagement? You don't provide any information about what your environment is, but using ServiceMix, I do this all the time. For example:

<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,该版本支持update-strategy设置.属性注入将找到setSetting(boolean setting)方法,并尝试将字符串转换为boolean值.这里指定了默认值"true",但是可以通过更改etc/myProps.cfg来覆盖它.

Note the inclusion of verion 1.1.0 of the blueprint-cm namespace, which supports the update-strategy setting. The property injection will find the setSetting(boolean setting) method and attempt to convert the string to the boolean value. Here the default value of "true" is specified, but that can be overridden with changes to etc/myProps.cfg.

这篇关于Osgi财产占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆