我对Spring和Camel有问题。

对不起,我无法粘贴真实代码...
因此,我试图使用占位符在 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 + "}}");

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

最佳答案

阅读方法的Javadoc,CamelContext上的getProperties不适合属性占位符。使用resolvePropertyPlaceholders作为属性占位符

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

08-04 10:20