啟動springboot應(yīng)用因未配置數(shù)據(jù)庫報錯的解決方案
啟動springboot應(yīng)用因未配置數(shù)據(jù)庫報錯
描述
創(chuàng)建一個全新的springboot項目,第一次啟動時報錯,具體錯誤信息如下所示:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-06-14 17:58:10.322 ERROR 12292 --- [ 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 classAction:
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).Process finished with exit code 1
解決方案
方案一
在application.properties配置文件中添加數(shù)據(jù)庫配置信息
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/guli?serverTimezone=GMT%2B8 spring.datasource.username=cx spring.datasource.password=123456
方案二
在啟動類頭部聲明進(jìn)行聲明:
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
springboot 1.5.8.RELEASE 版本啟動報錯
起因
新建spring boot項目選擇1.5.8.RELEASE版本后生成項目,配置好application.properties后啟動項目,報錯。
Caused by: java.lang.ClassNotFoundException: org.springframework.core.env.EnvironmentCapable
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
錯誤排查
1.ctrl+shift+t查找后,發(fā)現(xiàn)沒這個類。
2.從這個類的全名不能發(fā)現(xiàn),這個類是屬于spring-core.jar下的。
3.在maven dependencies中查看spring-core的版本是4.3.12.RELEASE
4.網(wǎng)上查詢可知spring-core4.3.12.RELEASE中沒有這個類。
解決方法
找到有這個類的spring-core版本。我用的是 4.3.9.RELEASE。然后在dependencies中加入
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.3.9.RELEASE</version> </dependency>
再次啟動就可以了。
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java面向?qū)ο缶幊讨衒inal關(guān)鍵字的使用方法詳解
這篇文章主要介紹了Java面向?qū)ο缶幊讨衒inal關(guān)鍵字的使用方法詳解,包括對內(nèi)部匿名類無法訪問外面的非 final 的變量問題的解讀,需要的朋友可以參考下2016-06-06