javaapache-camel

Camel 3 -> 4 unitOfWork


I am trying to update from camel 3 to 4, but i have an issue with the following line,

camelContext.adapt(ExtendedCamelContext.class).setUnitOfWorkFactory(new CustomUnitOfWorkFactory());

I found already this post: Apache Camel adapt() method removed in version 4 So with the help of that I transformed it into:

    ExtendedCamelContext context = camelContext
            .getCamelContextExtension()
            .getContextPlugin(ExtendedCamelContext.class);

but on the extended camel context the setUnitOfWorkFactory doesnt seem to be available anymore.

Does someone know how to set this in camel 4.6


Solution

  • In the end the solution was quite simple.

    if you dont use spring boot

    camelContext.getRegistry().bind("customUnitOfWorkFactory", new CustomUnitOfWorkFactory());
    

    if you use spring boot make it a component

    @Component
    public class CustomUnitOfWorkFactory implements UnitOfWorkFactory {