我正在使用 Camel-HTTP4 2.10.4 组件从我的应用程序调用远程 REST 服务。此通信需要 SSL 配置。我成功使用 resource
和 password
的硬编码值测试了我的配置。
现在我需要使用camel的Property-Placeholder进行相同的配置。我在 spring 配置中使用嵌套属性。例如:
${${env:${default.fallback.env}}.path.to.keystore}
我关注了Using PropertyPlaceholder并定义
<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="locations">
<list>
<ref bean="confgPath1" />
<ref bean="configPath2" />
</list>
</property>
</bean>
和sslContext参数如下
<camel:sslContextParameters id="sslContextParameters">
<camel:trustManagers>
<camel:keyStore resource="{{{{default.fallback.env}}.keystore.file}}"
password="{{{{default.fallback.env}}.keystore.password}}" />
</camel:trustManagers>
<camel:keyManagers keyPassword="{{{{default.fallback.env}}.keystore.password}}">
<camel:keyStore resource="{{{{default.fallback.env}}.keystore.file}}"
password="{{{{default.fallback.env}}.keystore.password}}" />
</camel:keyManagers>
<camel:clientParameters>
<camel:cipherSuitesFilter>
<camel:include>.*</camel:include>
</camel:cipherSuitesFilter>
</camel:clientParameters>
</camel:sslContextParameters>
我的应用程序在启动时成功加载 spring 上下文。但到达端点后我收到错误:
Failed to resolve endpoint <<My remote service URL>> due to: Error parsing property value: {{{{default.fallback.env}}.keystore.password}}.
我可以使用 Camel 的属性占位符来表示简单的属性。例如
{{default.fallback.env}}
但是,当我尝试使用嵌套属性时,它给出了上述指定的错误。帮我找出解决这个问题的正确方法。
最佳答案
当前的camel属性组件不支持嵌套属性,所以我就填个JIRA为了它。
由于Camel属性首先不支持嵌套属性,因此您可以像这样定义属性文件,并从系统属性设置环境并使用{{someproperty}}来引用属性。
someproperty={{{{environment}}.someproperty}}
# LOCAL SERVER
junit.someproperty=junit
# LOCAL SERVER
local.someproperty=local
# TEST
test.someproperty=test
# PROD
prod.someproperty=prod
关于java - Camel 属性-占位符 : Not able to configure `camel:sslContextParameters` with nested properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22814272/