Enterprise Integration Zone is brought to you in partnership with:

I'm in my mid forties and living in East Devon, UK. I enjoy explaining technology without all the buzz words and jargon. Col is a DZone MVB and is not an employee of DZone and has posted 13 posts at DZone. You can read more from them at their website. View Full User Profile

Apache Camel - Connection Beans Without Spring

03.04.2013
| 2901 views |
  • submit to reddit
While writing some tests for an Apache Camel project, I just spent rather longer than I'd have liked trying to work out how to configure a connection bean for Mongo without using Spring.

Since I hide my embarrassments in public I thought I'd best share with anyone else with brain freeze.
public class SomeTest extends CamelTestSupport {

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:findAll")
                    .to("mongodb:myConnectionBean?database=flights&collection=tickets&operation=findAll")
                    .to("mock:resultFindAll");

            }
        };
    }

    @Override
    protected JndiRegistry createRegistry() throws Exception {
        JndiRegistry reg = new JndiRegistry(createJndiContext());
        Mongo connectionBean = new Mongo("localhost", 27017);
        reg.bind("myConnectionBean", connectionBean);
        return reg;
    }

    @Test
    public void testSomething() throws InterruptedException {
        // test something here
    }

}
Don't forget you need the camel-mongodb artifact in your pom.xml file. Good luck fellow travellers.

Published at DZone with permission of Col Wilson, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)