how to create datasource using camel?

℡╲_俬逩灬. 提交于 2019-12-03 08:10:29

There is the SQL example which shows how to setup a DataSource

Yes that examples using Spring XML. But how you setup the DataSource can be done in Java code also. Then you need to register the DataSource in the Camel Registry.

For example you can use a JndiRegistry or the SimpleRegistry. The latter is easier.

Here is some pseudo code showing the principle, of creating a registry, add your beans into this registry, and then providing the registry to the constructor of DefaultCamelContext.

SimpleRegistry registry = new SimpleRegistry();

// code to create data source here
DateSource ds = ...

registry.put("myDataSource", ds);

CamelContext camel = new DefaultCamelContext(registry);

So silly me! I had not included camel-jdbc-2.12.1.jar in the CLASSPATH. Now above examples work.

Spring was mentioned there just because it is very useful paradigm of working with DB (mainly because of templates introduced by Spring Framework.) Of course you can hook up the standard JDBC connection and implement DAO by yourself - nothing wrong with that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!