【问题标题】:How to define an MS SQL datasource for use in apache camel?如何定义用于 apache camel 的 MS SQL 数据源?
【发布时间】:2020-11-02 18:51:45
【问题描述】:

我正在尝试创建一个与 Apache camel sql 组件一起使用的数据源,并且根据 documentation 我已经定义了 spring 数据源属性和 在我的 pom 文件中包含依赖项:

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

我什至根据大量读取示例定义了一个配置的数据源(尽管如果我没记错的话,如果定义了 spring 默认数据源属性,则不需要这样做):

@Configuration
public class DataSourceConfig {

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

到目前为止,我的努力都导致了同样的错误:

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

我很感激一些关于我缺少什么的指针。

编辑:

我定义的数据源属性:

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

【问题讨论】:

  • 你能告诉我们你的数据源属性吗?您是否能够通过 JDBC 连接到您的 SQL 服务器,例如与松鼠或 DBeaver?您确定您的 SQL Server 已配置为接受 TCP 连接吗?
  • 是的,我可以通过 DBeaver 连接到数据库。

标签: java sql-server spring spring-boot apache-camel


【解决方案1】:

我解决了。我查看了DataSourceBuilder source 并看到构建方法试图确定类型,所以我在实例化中指定了一个并且它起作用了:

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

【讨论】:

    猜你喜欢
    • 2020-06-13
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    相关资源
    最近更新 更多