从java bean获取CamelContext参数

时间:2013-12-05 17:18:42

标签: java spring apache-camel

我遇到了Spring和Camel的问题。

对不起,我无法粘贴真实代码...... 所以,我试图通过占位符获取驼峰上下文中定义的属性。但属性为空。

<bean id="mySuperClass"
        class="com.lol.rofl.MySuperClass">
</bean>
<camelContext id="blablabla" xmlns="http://camel.apache.org/schema/spring">
<propertyPlaceholder id="myProp"
        location="classpath:camel/contexts/myprops.properties" />
....
Some fantastique code that use the properties and works.
....
</camelContext>

.java:

public class MySuperClass implements CamelContextAware
{

    public void getCCProperties()
    {
           final Map<String, String> camelContextProperties = camelContext.getProperties();
            crawlerOutputDirectory = camelContextProperties.get("my.super.pro");
    }
}

我只是觉得我没有尝试正确的方式,谢谢你的帮助


placeHolders中的属性可以通过以下方式找到:

camelContext.resolvePropertyPlaceholders("{{" + propertyName + "}}");

ex:camelContext.resolvePropertyPlaceholders("{{output.directory}}");

1 个答案:

答案 0 :(得分:2)

读取方法的javadoc,CamelContext上的getProperties不适用于属性占位符。使用resolvePropertyPlaceholders作为属性占位符

CamelContext的javadoc:http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContext.html