【问题标题】:Get Hostname in Apache Camel Spring DSL configuration file在 Apache Camel Spring DSL 配置文件中获取主机名
【发布时间】:2013-07-30 12:48:53
【问题描述】:

我想为每个机器/主机名加载配置属性。

我有几个属性文件作为资源,我希望 Apache Camel 根据机器的主机名加载特定的属性文件。

主机名1:sql-hostname1.properties,paths-hostname1.properties

主机名2:sql-hostname2.properties、paths-hostname2.properties

我正在使用 Camel propertyPlaceholder

<propertyPlaceholder id="placeholder"
        location="classpath:sql-hostname1.properties,
                  classpath:paths-hostname1.properties" />

我试图将主机名作为环境属性 ${env:hostname} 或系统属性 ${hostname} 获取,但没有任何效果。

有什么想法吗?

【问题讨论】:

  • sql-${sysenv.computername}.properties 完美运行。我更喜欢主机名属性,因为 Linux 系统上不存在“COMPUTERNAME”
  • 您也可以使用容器的任何预定义环境变量。对于不同的主机,此变量可能不同。

标签: java spring apache-camel


【解决方案1】:

如何配置一个spring bean,并使用spring 表达式语言来获取主机名?参见例如this blog post

【讨论】:

  • 谢谢! &lt;bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent"&gt; &lt;property name="location" value="classpath:config-#{inetAddress.hostName}.properties" /&gt; &lt;/bean&gt; &lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt; VS &lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt; &lt;propertyPlaceholder id="placeholder" location="classpath:config-#{inetAddress.hostName}.properties" /&gt;
  • 第一个有效,第二个无效。 #{something} 在 Spring DSL 的 Camel 上下文中尚不支持。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-05
  • 1970-01-01
  • 2012-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多