網站首頁 編程語言 正文
Springboot Druid 啟動報錯:Failed to configure a DataSource: ‘url‘ attribute is not specified, 問題解決方案
作者:DangerShi 更新時間: 2022-07-12 編程語言背景:
該應用(下文中用app代替)之前版本由其他同事已經發布上線過,正常使用中,本次升級了其中依賴的公司某個sdk的版本(下文中用a.jar代替),結果出現應用啟動報錯,報錯信息如下:
ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xxx':…………(略)
Related cause: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
…………(略)
***************************
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 (the profiles qa are currently active).
排查過程:
1、網上最容易查到的解答(來自stackoverflow),在啟動類上的注解加如下配置:
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }
這種方式針對的是應用中不需要使用數據庫的場景,而我們的應用是要使用數據庫的,所以并不適用。
2、既然要使用數據庫,而報錯又是數據庫url未配置,那就檢查數據庫的配置吧。
檢查application.properties中的數據庫配置是否正確,注意檢查格式和內容;經檢查,該配置無誤(該應用之前正常發布上線,數據庫配置本次未做調整);
3、繼續檢查應用的配置,
項目的Application啟動類中有如下注解:
@ImportResource({"classpath*:spring/applicationContext.xml"})
所以檢查applicationContext.xml中的配置,如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="classpath*:spring/dataSource.xml"/>
<import resource="classpath*:dubbo/beans-dubbo-consumer.xml"/>
</beans>
檢查發現,dataSource.xml的路徑配置與實際路徑不一致(dataSource.xml中內容的是DruidDataSource配置),并不在spring文件夾下,實際路徑為:classpath*:dataSource.xml,修改后該報錯消失,應用啟動成功。
4、仍然有個疑惑,為什么升級a.jar版本之前,該應用啟動正常呢?
排查之前的配置,發現原來在低版本a.jar的pom中引入了b.jar, 而b.jar中是存在spring/dataSource.xml的,應用app與b.jar都是公司同一個業務域下的組件,使用的是同一個數據庫,所以歪打正著的使app正常啟動(坑啊~)。但由于a.jar中本來是不需要依賴b.jar的,所以a在本次升級的時候,pom中去掉了b.jar的依賴,從而導致了app升級后無法正常啟動了。
以上,問題搞定!
原文鏈接:https://blog.csdn.net/jian876601394/article/details/125149405
相關推薦
- 2022-12-27 Golang中int,?int8,?int16,?int32,?int64和uint區別淺析_Gol
- 2022-07-25 pytest中配置文件pytest.ini使用_python
- 2021-12-11 Redis之sql緩存的具體使用_Redis
- 2023-01-18 解讀Scrapy回調函數callback傳遞參數的方式_python
- 2022-06-08 Api接口Sign簽名和驗簽
- 2022-09-28 Dephi逆向工具Dede導出函數名MAP導入到IDA中的實現方法_python
- 2022-08-30 DOM節點對象 、獲取節點、節點屬性、動態操作DOM節點、toList1.0/toList2.0、
- 2022-06-01 Go中的gRPC入門教程詳解_Golang
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支