spring - 使用 camel http4 的系统属性代理设置

标签 spring http proxy apache-camel system-properties

我尝试使用系统属性的 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/

相关文章:

Ruby CGI 重定向响应,无需等待脚本结束

laravel - vagrant laravel homestead http服务器IP地址

java - 请求参数的存在应评估为真

delphi - 检测 IE 代理设置并与 TIdHTTP 一起使用

node.js - 指定根文件夹 express-http-proxy

java - 在不更改代码的情况下将代理添加到网络应用程序可能吗?

java - Autowiring 字段为空,但在构造函数 Autowiring 时不是

java - jdbctemplate - queryForList - 传递日期?

javax.transaction.Transactional 与 org.springframework.transaction.annotation.Transactional

java - Maven 干净安装 jar 和 war