suitej
suitej

Reputation: 99

Apache Camel 3.x + Spring Boot + JDBC DataSource: java.lang.IllegalStateException: No supported DataSource type found

This is no doubt a configuration/dependency issue.

failing code snippet

@Bean
@ConfigurationProperties(prefix="rmw.datasource")
public DataSource getDataSource() {
    return DataSourceBuilder.create().build();
}

application.properties

rmw.datasource.url=jdbc:sqlserver://123.123.123.123
rmw.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
rmw.datasource.username=xxxx
rmw.datasource.password=zzzz
rmw.datasource.platform=sqlserver

I have tried with and without rmw.datasource.platform=sqlserver - it makes no difference.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>biz.suitej.poc</groupId>
    <artifactId>http-producer</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
    <java.version>1.11</java.version>
    <camel.version>3.1.0</camel.version>
    <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
    </properties>

    <dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-spring-boot-dependencies</artifactId>
            <version>${camel.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
    </dependencyManagement>

    <dependencies>

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

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

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

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

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

    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>8.2.2.jre11</version>
    </dependency>
    </dependencies>

    <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>
        </plugin>
    </plugins>
    </build>

</project>

I have camel-jdbc-starter and mssql-jdbc JDBC driver.

I have tried camel-sql-starter and get the same error.

console output

2020-06-17 13:15:45.978  WARN 128833 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getDataSource' defined in class path resource [c10y/sql/query/GetRemodelWorksRouteBuilder.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
2020-06-17 13:15:45.998  INFO 128833 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-06-17 13:15:46.009 ERROR 128833 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getDataSource' defined in class path resource [c10y/sql/query/GetRemodelWorksRouteBuilder.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
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:484) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
...

The solution listed elsewhere to add spring-boot-starter-data-jpa didn't work for me (it just returned a different error):

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <version>1.5.6.RELEASE</version>
</dependency>

I'm baffled why this just doesn't work 'straight out of the box'.

Thanks in advance for your help.

Upvotes: 2

Views: 1336

Answers (1)

suitej
suitej

Reputation: 99

Just after posting this I found the solution that worked for me:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
    <version>1.5.6.RELEASE</version>
</dependency>

Upvotes: 1

Related Questions