【发布时间】:2015-10-13 12:18:11
【问题描述】:
我有一个项目,我在其中使用spring-boot-jdbc-starter,它会自动为我配置一个数据源。
现在我将camel-spring-boot 添加到项目中,我能够成功地从RouteBuilder 类型的Beans 创建路由。
但是当我使用骆驼的 sql 组件时,它找不到数据源。有什么简单的方法可以将 Spring 配置的数据源添加到CamelContext?在骆驼项目的示例中,他们使用 spring xml 进行数据源配置,但我正在寻找一种使用 java config 的方法。这是我尝试过的:
@Configuration
public class SqlRouteBuilder extends RouteBuilder {
@Bean
public SqlComponent sqlComponent(DataSource dataSource) {
SqlComponent sqlComponent = new SqlComponent();
sqlComponent.setDataSource(dataSource);
return sqlComponent;
}
@Override
public void configure() throws Exception {
from("sql:SELECT * FROM tasks WHERE STATUS NOT LIKE 'completed'")
.to("mock:sql");
}
}
【问题讨论】:
-
我的不好,不需要 sqlComponent Bean。由于 CamelContext 可以访问所有 spring bean 只需在 sql 端点的末尾添加
?dataSource=dataSource即可按预期工作 -
您应该将该评论作为答案发布并接受它:)
标签: jdbc spring-boot apache-camel