- 添加依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
- 在application.properties中添加数据库信息 项目启动后,springboot会自动配置datasource bean。
spring.datasource.driver-class-name = <driverName>
spring.datasource.url = <url>
spring.datasource.username = <username>
spring.datasource.password = <password>
- 在route中使用datasource JDBC component不能在producer中使用
from("timer://mytimer?fixedRate=true&period=10s")
.log("TESTING")
.setBody(constant("EXEC SP_Manuals @DocumentRef = 'xyz1234' , @Year = '2019'"))
.to("jdbc:dataSource") //dataSource是默认创建的bean名
如果使用.to(jdbc:datasource)会出现以下错误。
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: datasource of type: javax.sql.DataSource
- 不要忘记添加camel-jdbc依赖项。
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jdbc</artifactId>
</dependency>