代码之家  ›  专栏  ›  技术社区  ›  Dark Star1

如何定义在apache camel中使用的mssql数据源?

  •  0
  • Dark Star1  · 技术社区  · 4 年前

    我正在尝试创建一个数据源,以便与apachecamelsql组件一起使用,并按照 documentation 在我的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
    
    0 回复  |  直到 4 年前
        1
  •  0
  •   Dark Star1    4 年前

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

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