Apache camel 驼峰SQL-在Spring引导中将数据源放入SimpleRegistry

Apache camel 驼峰SQL-在Spring引导中将数据源放入SimpleRegistry,apache-camel,datasource,camel-sql,Apache Camel,Datasource,Camel Sql,我使用SpringBoot启动一个camel路由,该路由使用camel sql查询MySQL数据库并调用REST服务 应用程序属性 db.driver=com.mysql.jdbc.Driver db.url=mysql://IP:PORT/abc db.username=abc db.password=pwd Application.java publicstaticvoidmain(字符串[]args){ run(WlEventNotificationBatchApplication.cl

我使用SpringBoot启动一个camel路由,该路由使用camel sql查询MySQL数据库并调用REST服务

应用程序属性

db.driver=com.mysql.jdbc.Driver
db.url=mysql://IP:PORT/abc
db.username=abc
db.password=pwd
Application.java

publicstaticvoidmain(字符串[]args){
run(WlEventNotificationBatchApplication.class,args);
}
DataSourceConfig.java

公共类数据源配置{
@值(“${db.driver}”)
公共字符串驱动程序;
@值(“${db.url}”)
公共字符串dbUrl;
@值(“${db.username}”)
公共字符串dbUserName;
@值(${db.password}”)
公共字符串密码;
@Bean(“数据源”)
公共数据源getConfig(){
DriverManager数据源dataSource=新的DriverManager数据源();
setdrivercassname(dbDriver);
setUrl(dbUrl);
setUsername(dbUserName);
setPassword(dbPassword);
返回数据源;
}
}
WLRouteBuilder.java

@组件
公共类WLRouteBuilder扩展了RouteBuilder{
@自动连线
私有NotificationConfig NotificationConfig;
@自动连线
私有数据源;
@凌驾
public void configure()引发异常{
发件人(“直接:事件通知”)
.to(“sql:”+notificationConfig.getSqlQuery()+“?dataSource=“+dataSource”)
.process(新的行映射器())
.log(“${body}”);
}
}
我在运行时看到以下错误,发现Camel无法在注册表中找到数据源bean。我不知道如何使用JavaDSL在SpringBoot中将“DataSource”注入注册表

?dataSource=org.springframework.jdbc.datasource.DriverManagerDataSource%40765367 due to: No bean could be found in the registry for: org.springframework.jdbc.datasource.DriverManagerDataSource@765367 of type: javax.sql.DataSource

它是Camel在uri中使用的bean的名称,在这里使用
语法引用它,如本文所述:(引用bean)

有点像

 .to("sql:"+notificationConfig.getSqlQuery()+"?dataSource=#dataSource"
其中,
dataSource
是创建
dataSource
的bean的名称,您可以给它另一个名称,例如

@Bean("myDataSource")
然后,骆驼SQL端点是

    .to("sql:"+notificationConfig.getSqlQuery()+"?dataSource=#myDataSource"

嗨,克劳斯,非常感谢你的回复。我能再问你一个问题吗。from(“sql:{list.sql}}?dataSource=#dataSource”).log(“进程行${body}”).end();在application.properties文件中,我包含了camel.springboot.main run controller=true。在按下CNTRL+C之前,路由将无限执行。如果删除camel.springboot.main-run-controller,camel将启动路由并停止主线程。无论如何,我可以让骆驼启动、执行路线并停止。希望我的问题清楚。提前谢谢!嗨,克劳斯,如果我遗漏了一些非常简单的东西,我很抱歉。我正在为这个应用程序使用Spring Boot。我尝试了从(“sql:{{list.eventnotification.sql}}?dataSource=#dataSource”).log(“processrow${body}”)到(“mock:bar”);并添加了getContext().stop();。由于application.properties中的camel.springboot.main run controller=true,路由仍然没有停止。在一个独立的Java应用程序中,我们启动route(camelcontext.start())并手动停止它。它在Spring Boot中是如何工作的?请帮助是的,我想在下一个2.18.1版本中有一个补丁。我可以做些什么,在Spring Boot中启动、处理和停止路由。我的代码要么运行无限路由循环(camel.springboot.main run controller=true),要么停止执行路由?