Search code examples
javaspring-bootapache-camelspring-camel

Error: Multiple RestConsumerFactory found on classpath


Getting error while calling addRouteDefinition. I am dynamically adding rest to camelcontext.

Error

org.apache.camel.FailedToCreateRouteException : Failed to create route ... because of Multiple RestConsumerFactory found on classpath. Configure explicit which component to use

RestsDefinition rests = camelContext.loadRestsDefinition(is);

camelContext.addRestDefinitions(rests.getRests());

for (RestDefinition restDefinition : rests.getRests()) {

        List<RouteDefinition> routeDefinitions = restDefinition.asRouteDefinition(camelContext);
        System.out.println(routeDefinitions);

        //camelContext.addRouteDefinitions(routeDefinitions);

        for (RouteDefinition route1 : routeDefinitions) {
            System.out.println("Route being Added : " + route1.getId());

            //Getting Error in this line
            camelContext.addRouteDefinition(route1);
        }
    }

Can anyone help me with this. Thank you.


Solution

  • The problem was with RestConfiguration as the RestConfiguration was not set correctly on camelcontext so added. camelContext.addRestConfiguration(restConfiguration);