在导入druid数据源时

在扩充数据源切换时spring.datasource.type类型根据源码所给的默许值修改后依旧报错

  • 先看源码:标色部分 ,  就是springboot所给的多少源 , 
    符合规律的话只要在计划文件中期维修改type值就足以  ,但是本身发掘不行
    依旧报错

    @ConditionalOnClass(org.apache.tomcat.jdbc.pool.DataSource.class)

    @ConditionalOnProperty(name = "spring.datasource.type", havingValue = "org.apache.tomcat.jdbc.pool.DataSource", matchIfMissing = true)
    static class Tomcat extends DataSourceConfiguration {
    
        @Bean
        @ConfigurationProperties(prefix = "spring.datasource.tomcat")
        public org.apache.tomcat.jdbc.pool.DataSource dataSource(
                DataSourceProperties properties) {
            org.apache.tomcat.jdbc.pool.DataSource dataSource = createDataSource(
                    properties, org.apache.tomcat.jdbc.pool.DataSource.class);
            DatabaseDriver databaseDriver = DatabaseDriver
                    .fromJdbcUrl(properties.determineUrl());
            String validationQuery = databaseDriver.getValidationQuery();
            if (validationQuery != null) {
                dataSource.setTestOnBorrow(true);
                dataSource.setValidationQuery(validationQuery);
            }
            return dataSource;
        }
    
    }
    
    /**
     * Hikari DataSource configuration.
     */
    @ConditionalOnClass(HikariDataSource.class)
    @ConditionalOnProperty(name = "spring.datasource.type", havingValue = "com.zaxxer.hikari.HikariDataSource", matchIfMissing = true)
    static class Hikari extends DataSourceConfiguration {
    
        @Bean
        @ConfigurationProperties(prefix = "spring.datasource.hikari")
        public HikariDataSource dataSource(DataSourceProperties properties) {
            HikariDataSource dataSource = createDataSource(properties,
                    HikariDataSource.class);
            if (StringUtils.hasText(properties.getName())) {
                dataSource.setPoolName(properties.getName());
            }
            return dataSource;
        }
    
    }
    
    /**
     * DBCP DataSource configuration.
     */
    @ConditionalOnClass(org.apache.commons.dbcp2.BasicDataSource.class)
    @ConditionalOnProperty(name = "spring.datasource.type", havingValue = "org.apache.commons.dbcp2.BasicDataSource", matchIfMissing = true)
    static class Dbcp2 extends DataSourceConfiguration {
    
        @Bean
        @ConfigurationProperties(prefix = "spring.datasource.dbcp2")
        public org.apache.commons.dbcp2.BasicDataSource dataSource(
                DataSourceProperties properties) {
            return createDataSource(properties,
                    org.apache.commons.dbcp2.BasicDataSource.class);
        }
    
    }
    
  • 错误音讯:本条错好三人付出的答案是让编辑器自动提示 
    而不和煦写
    就不会现出(显著极其的),value值是springboot源码上自带的,因而也不会错,可是为啥会报错呢?

    Description:

    Failed to bind properties under ‘spring.datasource.type’ to java.lang.Class:

    Property: spring.datasource.type
    Value: org.apache.commons.dbcp2.BasicDataSource
    Origin: class path resource [application.yml]:7:11
    Reason: No converter found capable of converting from type [java.lang.String] to type [java.lang.Class<javax.sql.DataSource>]
    

    Action:

    Update your application’s configuration

  • 原因:

在导入druid数据源时。在导入druid数据源时。在导入druid数据源时,也正是外界数据源,我们必需导入相关信任,因而作者尝试将springboot默许数据源的相关信赖也导入

  • 引入(maven):


    org.apache.commons
    commons-dbcp2
    2.2.0

 

  • 结果:在导入druid数据源时。看调节台出口—nice(解决)

图片 1

 

  • 再有正是springboot2.0.2.RELEASE版本私下认可的数据源而不是org.apache.tomcat.jdbc.pool.DataSource,而是:com.zaxxer.hikari.HikariDataSource

故此除了com.zaxxer.hikari.HikariDataSource不用额外引进依赖,别的的数据源都要引入注重

  • http://mvnrepository.com:在那个网站中输入要引进的借助,粘贴到pom中就ok了

You may also like...

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图