Skip to content
Advertisement

How to define an MS SQL datasource for use in apache camel?

I am trying to create a data source for use with the Apache camel sql component and as per the documentation I have defined the spring data source properties and included the dependencies in my pom file:

        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-jdbc-starter</artifactId>
        </dependency>

        <!-- Component dependencies-->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-sql-starter</artifactId>
        </dependency>

        <!-- MS SQL jdbc driver -->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>8.2.2.jre11</version>
        </dependency>

I have even defined a configured a data source as per numerous read examples (though if I am not mistaken, this isn’t needed if the spring default datasource properties are defined):

@Configuration
public class DataSourceConfig {

    @Bean(name = "etlDataSource")
    @ConfigurationProperties("spring.datasource")
    public DataSource getDataSource(){
        return DataSourceBuilder.create().build();
    }
}

So far my efforts, all result in the same error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'etlDataSource' defined in class path resource [com/test/camel/etl/config/DataSourceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'getDataSource' threw exception; nested exception is java.lang.IllegalStateException: No supported DataSource type found

I’d appreciate some pointers as to what I am missing.

EDIT:

My datasource properties as defined:

spring:
  datasource:
    password: some_passw0rd
    url: jdbc:sqlserver://localhost:1433;trustServerCertificate=false;loginTimeout=30;
    username: sa
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
    platform: mssql

Advertisement

Answer

I solved it. I looked into the DataSourceBuilder source and saw that the build method tries to determine the type, so I specified one in the instantiation and it worked:

    @Bean(name = "etlDataSource")
    @ConfigurationProperties("spring.datasource")
    public DataSource getDataSource(){
        return DataSourceBuilder.create().type(BasicDataSource.class).build();
    }
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement