mongodb://localhost:27017/testdb
import org.apache.camel.builder.RouteBuilder;
public class MyRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:saveToMongo")
.to("mongodb:myDb?database=testdb&collection=myCollection");
}
}
import org.apache.camel.component.mongodb.MongoDbComponent;
public class MyApp {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
// Register the MongoDB component
MongoDbComponent mongo = new MongoDbComponent();
mongo.setMongoConnection("mongodb://localhost:27017");
context.addComponent("mongodb", mongo);
// Start the context and add the routes
context.start();
context.addRoutes(new MyRouteBuilder());
Thread.sleep(10000);
context.stop();
}
}
以上就是解决'Apache Camel route with MongoDB gives an error No bean could be found in the registry”问题的方法。