Apache Camel 3.x + Spring Boot + JDB C DataSource: java .lang.IllegalStateException: поддерживаемый тип DataSource не найден - PullRequest
2 голосов
/ 17 июня 2020

Это, без сомнения, проблема конфигурации / зависимости.

фрагмент кода с ошибкой

@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

Пробовал с rmw.datasource.platform = sqlserver - без разницы.

пом. 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>

У меня есть camel-jdb c -starter и ms sql -jdb c JDB C драйвер.

Я попробовал camel- sql -starter и получил ту же ошибку.

вывод консоли

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]
...

Решение, указанное в другом месте для add spring-boot-starter-data-jpa не сработал для меня (он просто вернул другую ошибку):

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

Я сбит с толку, почему это просто не работает работать «прямо из коробки».

Заранее благодарим за помощь.

1 Ответ

1 голос
/ 17 июня 2020

Сразу после публикации я нашел решение, которое сработало для меня:

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