. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.7.RELEASE)
2019-08-27 11:31:57.774 ERROR 15364 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
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).
解析:
搭建基於SpringBoot ,springCloud 框架簡單入門 的測試。報錯如上:
原因:
這是因為添加了數據庫組件,所以autoconfig會去讀取數據源配置,而新建的項目還沒有配置數據源/URL地址錯誤,所以會導致異常出現。
解決方案:
一。 在啟動類的@EnableAutoConfiguration或@SpringBootApplication中添加exclude = {DataSourceAutoConfiguration.class},排除此類的autoconfig。啟動以后就可以正常運行。
1 @MapperScan("com.wsc.core.mapper")//映射mapper地址 2 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
//啟動類 SpringBoot 3 public class Start { 4 public static void main(String[] args) { 5 SpringApplication.run(Start.class,args); 6 } 7 }
二。application.yml中的URL地址識別不出來,格式寫錯。
yaml格式文件的寫入 要求嚴格 (等階平齊,頂格輸入)

1 server: 2 port: 8001 3 mybatis: 4 config-location: classpath:mybatis/mybatis.cfg.xml #mybatis 配置文件路徑 5 type-aliases-package: com.wsc.core.pojo # entity別名類所在包 6 mapper-locations: mybatis/mapper/*.xml # mapper映射文件 7 spring: 8 application: 9 name: microserver-product #這個很重要,這在以后的服務與服務之間相互調用一般都是根據這個name 10 datasource: 11 type: com.alibaba.druid.pool.DruidDataSource 12 driver-class-name: com.mysql.cj.jdbc.Driver 13 url: jdbc:mysql://127.0.0.1:3306/springcloud_db01?serverTimezone=GMT%2B8 14 password: wsc 15 username: root 16 dbcp2: 17 min-idle: 5 # 數據庫連接池的最小維持連接數 18 initial-size: 5 # 初始化連接數 19 max-total: 5 # 最大連接數 20 max-wait-millis: 150 # 等待連接獲取的最大超時時間