Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could

1、问题概述?

今天在使用springboot+jpa+shardingsphere实现分布式分库分表配置的时候,启动任务的时候出现了如下问题:

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class
Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
翻译后:

  未能配置DataSource:未指定“url”特性,也无法配置任何嵌入的数据源。

未能配置DataSource:未指定“url”特性,也无法配置任何嵌入的数据源。

原因:无法确定合适的驱动程序类别

操作:

考虑以下内容:

如果您想要一个嵌入式数据库(H2、HSQL或Derby),请将其放在类路径中。

如果您有要从特定配置文件加载的数据库设置,则可能需要激活它(当前没有激活的配置文件)。

2、我的datasource配置

我可以确信,我的配置是没有问题的。

spring.shardingsphere.datasource.names=ds-0,ds-1

spring.shardingsphere.datasource.ds-0.type= com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds-0.driver-class-name= com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds-0.url= jdbc:mysql://localhost:3306/ds_0?serverTimezone=UTC&useSSL=false
spring.shardingsphere.datasource.ds-0.username= root
spring.shardingsphere.datasource.ds-0.password= 123456

spring.shardingsphere.datasource.ds-1.type= com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds-1.driver-class-name= com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds-1.url= jdbc:mysql://localhost:3306/ds_1?serverTimezone=UTC&useSSL=false
spring.shardingsphere.datasource.ds-1.username= root
spring.shardingsphere.datasource.ds-1.password= 123456

3、解决办法

这个问题主要还是使用了多数据源的情况而引发的问题。

在启动类上加:(exclude= {DataSourceAutoConfiguration.class})

DataSourceAutoConfiguration.class会自动查找applications文件中与数据源配置相关的信息。
尤其是我们在使用多数据源的时候需要加上这个配置,排除自动配置,实现自动注入数据源配置。

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

 

 

  • 8
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雾林小妖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值