日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

springboot報錯Error creating bean with name ‘dataSource‘的解決方案

作者:Mutig_s 更新時間: 2024-03-22 編程語言

問題描述:

在學習到黑馬的學成在線微服務項目時,運行內容模塊的服務時報錯如下:

org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'dataSource': 
Unsatisfied dependency expressed through field 'basicProperties'; 
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties':
Instantiation of bean failed; 
nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: 
Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType
	

報錯異常分析:

Spring應用程序中名為“dataSource”的bean的依賴項注入存在問題。具體問題在于“dataSource”bean的“basicProperties”字段。此字段有一個未滿足的依賴項。

嵌套異常進一步解釋了此錯誤的根本原因,該異常表示“DataSourceProperties”bean的實例化失敗。它遇到“BeanInstanceException”,其中“DataSourceProperties”類的構造函數引發了異常。此異常的根本原因是類“org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType”的“NoClassDefFoundError”。

“NoClassDefFoundError”表明運行時在類路徑上找不到類“EmbeddedDatabaseType”。這個類通常是spring Framework中“spring-jdbc”模塊的一部分。

要解決此問題,應確保在項目的生成配置中正確包含必要的依賴項。具體來說,您需要確保在構建文件(例如,Maven的pom.xml或Gradle的build.Gradle)中正確指定了“spring-jdbc”依賴項。

解決問題:

對于Maven,您可以在pom.xml中添加以下依賴項:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

對于Gradle,那可以在build.gradle中添加一下依賴:

implementation 'org.springframework.boot:spring-boot-starter-jdbc'

原文鏈接:https://blog.csdn.net/qq_62923382/article/details/130728274

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新