If you are talking about unit testing, simply override the "createRegistry()" method as in [1].
If you are talking about the real application, simply define the datasource in your spring xml and use the endpoint uri "jdbc:<spring_bean_id_of_your_datasource_bean>". Look at [2] and [3] for an example. [1] https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/AbstractJdbcTestSupport.java [2] https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcSpringAnotherRouteTest.java [3] https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/resources/org/apache/camel/component/jdbc/camelContext.xml Best, Christian On Mon, Mar 26, 2012 at 3:06 PM, sekaijin <[email protected]>wrote: > Hello, > I can not run camel-jdbc in java. > > I defines a route with camel-blueprint, via a road builder (not in XML) > because I know the road to be built when bundle start. > > when starting the bundle, I read a database that contains definitions of > endpoints. with there informations, I build the road. where in the database > I have a record defining an endpoint jdbc datasource I create a datasource > "myDataSourceName" and the uri "jdbc:myDataSourceName" > > in the documentation I've read, I had to do > JndiRegistry reg = super.createRegistry(); > reg.bind("testdb", db); > return reg; > > but I'm in the configure method or in constructor of route builder > I can not call super.createRegistry(); the register already exists > I tried context.getRegistry (); who gets a JndiRegistry but getRegistry() > return a simple Registry. > The bind method does not exist on Registry. > I tried (JndiRegistry) context.getRegistry(); > but I get a CastException. > > public RouteBuilder() > super(); > inUrl = getParameter("input.url"); > //... read configuration datas > DataSourceName = "myDataSourceName"; > > DataSource DS = DataSourceFactory.create(DataSourceName, ....); //using > pooled datasource factory (c3p0) > > JndiRegistry reg = (JndiRegistry) getContext().getRegistry(); > //CastException > reg.bind("myDataSourceName", reg);// > //Or > Registry reg = getContext().getRegistry(); > reg.bind("myDataSourceName", reg);//compil error bind is not method of > Registry > > dsUri = "jdbc:" DataSourceName; > } > > public void configure() { > RouteDefinition r = from(inUrl); > if ("sommeValue".equals(sommeParameter) {} > r.bean(MyBean.class); > //... > r.to("dsUri) > > > > I have a similar problem in JUnit > CamelTestSupport created a camelContext and a Registry > then create the RouteBuilder (calls constructor) > and calls the configure() method > > I've created an object datasource but inpossible to put it in the registry. > > can you help me ? > A JYT > PS: Sorry for my approximative english > > -- > View this message in context: > http://camel.465427.n5.nabble.com/How-to-register-a-datasource-on-configure-method-or-constructor-of-a-RoutBuilder-tp5595165p5595165.html > Sent from the Camel - Users mailing list archive at Nabble.com.
