In an app I’m working on we have a need to make sure that all
CamelContext’s have some default configurations on them. We are using
CamelConfiguration. It would be best in our case if we could do this
configuration though spring. This is what I did after looking for an
existing solution.



I defined an interface like this:

*public* *interface* CamelContextConfigVisitor {

    *public* CamelContext config(CamelContext camelContext);

}



Then I sub-classed CamelConfiguration and did this override:

@Override

*protected* CamelContext createCamelContext() *throws* Exception {

    CamelContext camelContext = *super*.createCamelContext();

   Map<String,CamelContextConfigVisitor> decorators =

         getApplicationContext().getBeansOfType(CamelContextConfigVisitor.
*class*);

   *for*(String name: decorators.keySet()){

      CamelContextConfigVisitor visitor =
getApplicationContext().getBean(name,

            CamelContextConfigVisitor.*class*);

      camelContext = visitor.config(camelContext);

   }

   *return* camelContext;

}



Is there an existing solution I could use?

Does this solution look ok?

Would it be possible to get this added code to the CamelConfiguration?

Reply via email to