I am using Spring Boot to initiate a camel route that uses Camel-sql to query MySQL DB and call a REST service.
application.properties
db.driver=com.mysql.jdbc.Driver
db.url=mysql://IP:PORT/abc
db.username=abc
db.password=pwd
Application.java
public static void main(String[] args) {
SpringApplication.run(WlEventNotificationBatchApplication.class, args);
}
DataSourceConfig.java
public class DataSourceConfig {
@Value("${db.driver}")
public String dbDriver;
@Value("${db.url}")
public String dbUrl;
@Value("${db.username}")
public String dbUserName;
@Value("${db.password}")
public String dbPassword;
@Bean("dataSource")
public DataSource getConfig() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(dbDriver);
dataSource.setUrl(dbUrl);
dataSource.setUsername(dbUserName);
dataSource.setPassword(dbPassword);
return dataSource;
}
}
WLRouteBuilder.java
@Component
public class WLRouteBuilder extends RouteBuilder {
@Autowired
private NotificationConfig notificationConfig;
@Autowired
private DataSource dataSource;
@Override
public void configure() throws Exception {
from("direct:eventNotification")
.to("sql:"+notificationConfig.getSqlQuery()+"?dataSource="+dataSource)
.process(new RowMapper())
.log("${body}");
}
}
I see the below error when I run, found out that Camel is unable to find DataSource bean in registry. I am quite not sure how to inject "DataSource" to Registry in Spring Boot using Java DSL.
?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