在导入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>]
    

    在导入druid数据源时。Action:

    在导入druid数据源时。Update your application’s configuration

  • 在导入druid数据源时。原因:

在导入druid数据源时,约等于外界数据源,大家亟须导入相关重视,因而笔者尝试将springboot暗许数据源的有关看重也导入

  • 在导入druid数据源时。引入(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了

发表评论

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