nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)


spring 整合 mybatis

報錯日志

Exception in thread "main" org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; 
nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect
3 times. Giving up.) ### The error may exist in file [E:\spring\out\production\spring\sqlmap\UserMapper.xml] ### The error may involve com.study.spring.dao.UserMapper.getUserCount ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection;
nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory
(Could not create connection to database server. Attempted reconnect
3 times. Giving up.)

造成這種錯誤的原因很多,比如數據庫連接信息錯誤

報錯前的jdbc.properties 和 application.xml

driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/mybatis?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
username=root password=root
 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${driver}"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${username}"/>
        <property name="password" value="${password}"/>
</bean>

修改成。。。。。。 username   -->  user

driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/mybatis?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
user=root password=root
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${driver}"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${user}"/>
        <property name="password" value="${password}"/>
</bean>

 

搜集了一下:

1、配置文件寫錯,比如是某個字母寫錯了,或者漏掉了 或者 db.properties文本格式不夠嚴謹

2、網絡不通導致的.因為是在遠程需要vpn. 碰到此問題可以先檢查下網絡

3、缺少 commons-dbcp jar包

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM