10.6. 添加 Fabric8 Karaf 蓝图支持
fabric8-karaf-blueprint
使用来自 fabric8-karaf-core
的 Aries PropertyEvaluator 和属性占位符来解析 Blueprint XML 文件中的占位符。
流程
要在自定义 Karaf 分发中包含蓝图支持的功能,请将
fabric8-karaf-blueprint
添加到pom.xml
项目的startupFeatures
部分。<startupFeatures> ... <feature>fabric8-karaf-blueprint</feature> ... </startupFeatures>
示例
fabric8 evaluator 支持串联的 evaluators,如 ${env+service:MY_ENV_VAR}
。您需要根据环境变量解析 MY_ENV_VAR
变量。然后,使用服务功能解析结果。例如,
<?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0" xsi:schemaLocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.3.0 http://aries.apache.org/schemas/blueprint-ext/blueprint-ext-1.3.xsd"> <ext:property-placeholder evaluator="fabric8" placeholder-prefix="$[" placeholder-suffix="]"/> <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"> <property name="userName" value="$[k8s:secret:$[env:ACTIVEMQ_SERVICE_NAME]/username]"/> <property name="password" value="$[k8s:secret:$[env:ACTIVEMQ_SERVICE_NAME]/password]"/> <property name="brokerURL" value="tcp://$[env+service:ACTIVEMQ_SERVICE_NAME]"/> </bean> </blueprint>
重要
嵌套属性占位符替换需要 Aries Blueprint Core 1.7.0
或更高版本。