最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot整合數(shù)據(jù)庫連接池Druid的錯誤詳解

 更新時間:2026年04月07日 08:50:47   作者:水星國王  
文章總結(jié)了幾種SpringBoot整合Druid時遇到的問題及其解決方法,主要問題有:缺少jar包導(dǎo)致系統(tǒng)停止和ClassNotFoundException,通過添加缺少的jar包可以解決問題,同時提醒注意數(shù)據(jù)庫配置信息的正確性和避免jar包沖突

前言

今天使用SpringBoot整合數(shù)據(jù)庫連接池Druid的錯誤總結(jié)的時候,遇到了幾個問題,都已經(jīng)解決,在這里分享給大家

發(fā)現(xiàn)和解決問題

在這些問題中,我會通過復(fù)制關(guān)鍵字和截圖的方式,幫助大家確實(shí)錯誤是否一致

問題1

如圖所示,控制臺顯示貌似已經(jīng)成功了,但是我們可以發(fā)現(xiàn),其實(shí)在啟動成功之后,因?yàn)橐粋€錯誤,導(dǎo)致系統(tǒng)停止了

問題1


想要解決這個問題,可以再加一個jar包

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>

這時候我們再次啟動,解決問題

問題1_圖2

問題2

關(guān)鍵日志:

Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType

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

Caused by: 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

問題2

解決這個問題,也是需要一個jar包

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>2.1.3.RELEASE</version>
        </dependency>

再次啟動解決問題

需要注意的地方

配置數(shù)據(jù)庫的相關(guān)信息的時候

注意用戶名和密碼,以及url,尤其是url,不同的庫以及版本不同,都會導(dǎo)致url出錯

還有就是jar包沖突,缺少jar包等

相關(guān)代碼

這里我把我的pom相關(guān)依賴和配置文件分享給大家

    <dependencies>
        <!--druid數(shù)據(jù)庫連接池-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.21</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>2.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.18</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.7.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>
    </dependencies>
spring.datasource.druid.url=jdbc:mysql://localhost:3306/test?serverTimezone=GMT&allowPublicKeyRetrieval=true&useSSL=false&characterEncoding=utf8
spring.datasource.druid.username=root
spring.datasource.druid.password=root
spring.datasource.druid.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.druid.initialSize=10
spring.datasource.druid.maxActive=20
spring.datasource.druid.maxWait=60000
spring.datasource.druid.minIdle=1
spring.datasource.druid.timeBetweenEvictionRunsMillis=60000
spring.datasource.druid.minEvictableIdleTimeMillis=300000
spring.datasource.druid.testWhileIdle=true
spring.datasource.druid.testOnBorrow=true
spring.datasource.druid.testOnReturn=false
spring.datasource.druid.poolPreparedStatements=true
spring.datasource.druid.maxOpenPreparedStatements=20
spring.datasource.druid.validationQuery=SELECT 1
spring.datasource.druid.validation-query-timeout=500
spring.datasource.druid.filters=stat
spring.datasource.druid.stat-view-servlet.enabled=true
# 訪問地址規(guī)則
spring.datasource.druid.stat-view-servlet.url-pattern=/druid/*
# 是否允許清空統(tǒng)計(jì)數(shù)據(jù)
spring.datasource.druid.stat-view-servlet.reset-enable=true
# 監(jiān)控頁面的登錄賬戶
spring.datasource.druid.stat-view-servlet.login-username=admin
# 監(jiān)控頁面的登錄密碼
spring.datasource.druid.stat-view-servlet.login-password=admin

總結(jié)

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

翁源县| 湘潭县| 石台县| 鄱阳县| 南涧| 镇康县| 安溪县| 桃源县| 芷江| 城步| 达孜县| 沁水县| 井陉县| 吉隆县| 桂林市| 仁化县| 湖州市| 通榆县| 云林县| 大渡口区| 六安市| 沙河市| 墨竹工卡县| 南开区| 汉中市| 汉寿县| 广宗县| 正安县| 安庆市| 手游| 正阳县| 凉城县| 古丈县| 香港 | 兴仁县| 涪陵区| 抚松县| 蓝山县| 丰镇市| 长岛县| 革吉县|