錯誤:
***************************
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-CSDN博客
無所謂了!長記性!浪費我體感時間三天!
感謝大佬↓?雖然和他給出的解決方法沒有任何關系 但是在瀏覽他的這篇文章的時候突然靈光一閃想到了依賴問題 淚流成河~~~~~~
springboot項目啟動報錯Failed to configure a DataSource: 'url' attribute is not specified and no embedde - MengW9 - 博客園 (cnblogs.com)