我遇到了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}}");
答案 0 :(得分:2)
读取方法的javadoc,CamelContext上的getProperties
不适用于属性占位符。使用resolvePropertyPlaceholders
作为属性占位符
CamelContext的javadoc:http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContext.html