【笔记】记一次读写分离之shardingsphere.datasource导致数据源为空错误

错误:

***************************
APPLICATION FAILED TO START
***************************

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).

表明 Spring Boot 没有找到任何可以配置的数据源。这可能是因为 spring.shardingsphere.datasource 配置项有误,或是缺少必要的数据库驱动

但是我应该写的都写了怎么会不行呢?

yml文件配置改了无数次!bean注入反复查看不是问题!

我也不知道度过了多少个小时但是我在这个部分卡了得有好久了……感觉半辈子在这里了

最后问题是发现sharding依赖版本不对 我原先用的是4.11.1版本

然后就使劲报错 我真的难受了 有苦说不出 

原因找到了结果困扰我那么久就这给人一种大餐是白馒头拉磨十天工资只有十块的落差感

把依赖版本换成下面这个就一切都解决了TT

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
    <version>4.0.0-RC1</version>
</dependency>

一个依赖搞出一系列问题 我都相似了哈哈哈哈哈哈哈总结起来心梗一下

===================================================

在这之前还有别的报错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shardingDataSource' defined in class path resource [org/apache/shardingsphere/shardingjdbc/spring/boot/SpringBootConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'shardingDataSource' threw exception; nested exception is java.lang.IllegalArgumentException: Data sources cannot be empty.
和Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'shardingDataSource' threw exception; nested exception is java.lang.IllegalArgumentException: Data sources cannot be empty.
和Caused by: java.lang.IllegalArgumentException: Data sources cannot be empty.
看着都心梗

这是因为在yml文件里同时配置了mysql本地数据库和虚拟机数据库(shardingphere的依赖作用就算是让项目于虚拟机mysql联系起来)

把本地的mysql配置语句全删了就行了

以及:

【笔记】对项目进行虚拟机上mysql主从复制后产生 Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required-优快云博客

无所谓了!长记性!浪费我体感时间三天!

感谢大佬↓ 虽然和他给出的解决方法没有任何关系 但是在浏览他的这篇文章的时候突然灵光一闪想到了依赖问题 泪流成河~~~~~~

springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde - MengW9 - 博客园 (cnblogs.com)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值