您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么解決啟動(dòng)springboot應(yīng)用因未配置數(shù)據(jù)庫(kù)報(bào)錯(cuò)問(wèn)題”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“怎么解決啟動(dòng)springboot應(yīng)用因未配置數(shù)據(jù)庫(kù)報(bào)錯(cuò)問(wèn)題”吧!
創(chuàng)建一個(gè)全新的springboot項(xiàng)目,第一次啟動(dòng)時(shí)報(bào)錯(cuò),具體錯(cuò)誤信息如下所示:
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ù)庫(kù)配置信息
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
方案二
在啟動(dòng)類(lèi)頭部聲明進(jìn)行聲明:
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
新建spring boot項(xiàng)目選擇1.5.8.RELEASE版本后生成項(xiàng)目,配置好application.properties后啟動(dòng)項(xiàng)目,報(bào)錯(cuò)。
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)沒(méi)這個(gè)類(lèi)。
2.從這個(gè)類(lèi)的全名不能發(fā)現(xiàn),這個(gè)類(lèi)是屬于spring-core.jar下的。
3.在maven dependencies中查看spring-core的版本是4.3.12.RELEASE
4.網(wǎng)上查詢可知spring-core4.3.12.RELEASE中沒(méi)有這個(gè)類(lèi)。
找到有這個(gè)類(lèi)的spring-core版本。我用的是 4.3.9.RELEASE。然后在dependencies中加入
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.3.9.RELEASE</version> </dependency>
感謝各位的閱讀,以上就是“怎么解決啟動(dòng)springboot應(yīng)用因未配置數(shù)據(jù)庫(kù)報(bào)錯(cuò)問(wèn)題”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)怎么解決啟動(dòng)springboot應(yīng)用因未配置數(shù)據(jù)庫(kù)報(bào)錯(cuò)問(wèn)題這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。