新建springboot項目啟動出錯 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.


錯誤信息入下:

2018-06-23 01:48:05.275  INFO 7104 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-06-23 01:48:05.355  INFO 7104 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-06-23 01:48:05.358 ERROR 7104 --- [           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).

這是因為添加了數據庫組件,所以autoconfig會去讀取數據源配置,而新建的項目還沒有配置數據源,所以會導致異常出現。

解決辦法:

1. 去掉數據庫依賴

2.在啟動類的@EnableAutoConfiguration或@SpringBootApplication中添加exclude = {DataSourceAutoConfiguration.class},排除此類的autoconfig。啟動以后就可以正常運行。

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)  
public class BdservoApplication {  
  
    public static void main(String[] args) {  
        SpringApplication.run(BdservoApplication.class, args);  
    }  
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM