Camel Event Logging With Spring Java Configuration

Here's how to set up a Camel EventNotifier which is managed by Spring Java Configuration. You may wish to do this if you EventNotifier implementation has further Spring-based dependencies of its own.

We can do this by having our Spring config extend CamelConfiguration:

public class MyConfig extends CamelConfiguration {

Then we can wire in our custom EventNotifier (and any other beans it requires):

public EventNotifier newEventNotifier() {
    CustomEventNotifier eventNotifier = new CustomEventNotifier();
    // etc.
    return eventNotifier;

Finally, and here's the critical part for Camel, we need to inject it into the CamelContext. We can do this by overriding CamelConfiguration's setupCamelContext method, which will do our work at the right time in the Spring+Camel lifecycle:

protected void setupCamelContext(CamelContext camelContext) {
    ApplicationContext ctx = getApplicationContext();
    ManagementStrategy mgtStrategy = camelContext.getManagementStrategy()  ;      
Posted on July 9, 2015 and filed under dev.