尝试连接到 mariDB 数据库时,我总是遇到以下异常,我无法弄清楚如何正确定义数据源。
No bean could be found in the registry for: myDataSource of type: javax.sql.DataSource
我的代码相当简单,如下所示:
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
String url = "jdbc:mariadb://localhost:3306/testDB";
BasicDataSource ds = new BasicDataSource();
ds.setUsername("user");
ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setPassword("password");
ds.setUrl(url);
SimpleRegistry registry = new SimpleRegistry();
registry.put("myDataSource", ds);
CamelContext context = new DefaultCamelContext(registry);
this.setContext(context);
//poll the mySQL Database every x minutes.
from("timer://Timer?period=6000")
.to("sql:select * from testDB?dataSource=myDataSource");
}
};
}
我已经尝试过定义数据源的蓝图版本,但也无法让它运行。
这是以正确的方式设置的吗?我可能缺少依赖项还是我指定了错误的驱动程序?