Spring Boot创建DataSource时遇到的错误:No supported DataSource type found

错误信息:

Spring Boot进行DataSource配置错误:No supported DataSource type found

原因:

DataSourceBuilder.create().build() 构建时未在classPath下找到数据源:

private static  MappedDataSourceProperties lookupPooled(ClassLoader classLoader,
				Class type) {
			MappedDataSourceProperties result = null;
			result = lookup(classLoader, type, result, "com.zaxxer.hikari.HikariDataSource",
					HikariDataSourceProperties::new);
		...................
			return result;
		}

解决办法:

pom.xml添加Hikari依赖


	com.zaxxer
	HikariCP

扩展:使用druidDataSource

引入依赖


	com.alibaba
	druid-spring-boot-starter
	1.1.10

示例:

    @Bean(name = "oldOrderDataSource")
    @Qualifier("oldOrderDataSource")
    @ConfigurationProperties(prefix="spring.datasource.old.order")
    public DataSource druidDataSource() {
        return DruidDataSourceBuilder.create().build();
    }

配置:

spring.datasource.druid.url=
//详情见:DruidDataSource 源码

你可能感兴趣的:(#,springboot,坑)