在整合ssm框架的时候,遇到了这样的报错:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
查阅了相关博客之后,发现了一个重要的关于
mysql-connector-java和mysql版本适配的问题。因为我的mysql版本为5.5,而在maven中配置的mysql-connector-java是8.0.11。 解决办法: 1.将mysql-connector-java改为5.1.37 2.spring的配置文件中,将driverClass的value改为com.mysql.jdbc.Driver。 如果msyql版本为6.0+,应该改为com.mysql.cj.jdbc.Driver
下图为mysql和connector版本兼容表