引用activemq.xml配置的{broker>部分中的属性

时间:2016-03-29 01:26:29

标签: activemq

是否可以在< broker>中引用我自己的属性? activemq.xml文件的配置部分?

我通过更改“env”脚本中的ACTIVEMQ_OPTS来设置我的属性值,例如添加如下内容:

ACTIVEMQ_OPTS="${ACTIVEMQ_OPTS} -Dmy.property=MyValue"

我在activemq.xml文件的开头有以下内容:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
  <!-- Allows us to use system properties as variables in this configuration file -->
  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <value>file:${activemq.conf}/credentials.properties</value>
    </property>
  </bean>

配置&lt; beans&gt;在activemq.xml文件中,在“值”中使用我自己的属性可以正常工作,例如:这很好用:

<bean id="myBean" class="MyClass">
    <property name="someProperty" value="${my.property}"/>
</bean>

和$ {my.property}已经完美解析了...但我无法弄清楚如何在&lt; broker&gt;内部解析我的属性元素或其中一个子元素(如persistenceAdapter)。

例如,在以下情况中......

<persistenceAdapter>
    <replicatedLevelDB directory="${activemq.data}/leveldb" zkAddress="${my.zk.address}" zkPath="/activemq" bind="tcp://0.0.0.0:0" weight="${my.weight}"/>
</persistenceAdapter>

... $ {activemq.data}属性已解析......但我似乎无法弄清楚如何在&lt; broker&gt;中解析我自己的任何属性activemq.xml配置文件的元素...我只是不断收到'$ {my.weight}'不是有效数字的错误(如果你考虑的话,这是一种侮辱; - )

2 个答案:

答案 0 :(得分:0)

是的,您可以使用属性占位符来加载属性文件或使用环境变量。看起来您正在使用Spring,因此您需要使用特定于Spring的属性占位符机制。

属性文件:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
         <property name="properties">
 ...

环境变量:

<context:property-placeholder />

另见: Spring property placeholders

答案 1 :(得分:0)

我遇到了同样的问题

让它工作但不确定这是否正确。

您必须将其添加到启动脚本中。

如果您使用的是active.bat

using System.Collections.Generic;

public static class LINQExtensions
{
    public delegate bool TryFunc<TSource, TResult>(TSource source, out TResult result);

    public static IEnumerable<TResult> SelectTry<TSource, TResult>(
        this IEnumerable<TSource> source, TryFunc<TSource, TResult> selector)
    {
        foreach (TSource item in source)
        {
            TResult result;
            if (selector(item, out result))
            {
                yield return result;
            }
        }
    }
}

如果您使用包装器,请将其添加到 wrapper.conf

"%_JAVACMD%" %ACTIVEMQ_SUNJMX_START% %ACTIVEMQ_DEBUG_OPTS% %ACTIVEMQ_OPTS% %ACTIVEMQ_SSL_OPTS% 
-Dactivemq.classpath="%ACTIVEMQ_CLASSPATH%" 
-Dactivemq.home="%ACTIVEMQ_HOME%" 
-Dactivemq.base="%ACTIVEMQ_BASE%" 
-Dactivemq.conf="%ACTIVEMQ_CONF%" 
-Dactivemq.data="%ACTIVEMQ_DATA%" 
-Djava.io.tmpdir="%ACTIVEMQ_TMP%" 
-D**remote.host.ip=1.2.3.4** 
-jar "%ACTIVEMQ_HOME%/bin/activemq.jar" %*

确保增加粗体数字。

相关问题