我尝试使用系统属性的 http4 组件代理设置无济于事。
documentation给出这个例子:
<camelContext>
<properties>
<property key="http.proxyHost" value="172.168.18.9"/>
<property key="http.proxyPort" value="8080"/>
</properties>
</camelContext>
但这只是使用硬编码值。
有没有办法在 camelContext 属性中使用占位符?
最佳答案
首先,您需要 PropertiesComponent解析 <camelContext>
中的属性:
<bean id="propertiesComponent" class="org.apache.camel.component.properties.PropertiesComponent" />
如果您只需要对以下其中一项的支持,则无需指定位置:
现在您可以在 camelContext 属性中使用占位符:
<camelContext>
<properties>
<property key="http.proxyHost" value="{{http.proxyHost}}"/>
<property key="http.proxyPort" value="{{http.proxyPort}}"/>
</properties>
</camelContext>
另一件需要注意的事情是,如果未设置系统属性,这将失败。您可以(并且可能应该)在冒号后指定一个默认值
<property key="http.proxyHost" value="{{http.proxyHost:}}"/>
<property key="http.proxyPort" value="{{http.proxyPort:}}"/>
确保它在这两种情况下都有效。
关于spring - 使用 camel http4 的系统属性代理设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31745003/