简体   繁体   中英

Getting CamelContext parameters from java bean

I have an issue with Spring and Camel.

I'm sorry I can't paste real code ... So, I'm trying to get properties defined in the camel Context with a placeholder. But the properties are Empty.

<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>

the .java :

public class MySuperClass implements CamelContextAware
{

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

I just think I'm not trying the right way, thanks for you help


SOLUTION

Properties in placeHolders can be found this way :

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

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

Read the javadoc of the methods, getProperties on CamelContext is not for property placeholder. Use resolvePropertyPlaceholders for property placeholder

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM