1. java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport
解决方式:添加spring-tx依赖,注意版本要一致,否则出现异常
Caused by: java.lang.IllegalStateException: No persistence exception translators found in bean factory. Cannot perform exception translation
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.14.RELEASE</version>
</dependency>
2. org.springframework.beans.MethodInvocationException: Property ‘dataSource’ threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy
解决方式:添加spring-jdbc依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.14.RELEASE</version>
</dependency>
3. Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ‘;serverTimezone=CTT’.
解决方式:检查数据库连接url的格式
// 正确格式
jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
4. Method com/mchange/v2/c3p0/impl/NewProxyPreparedStatement.isClosed()Z is abstract
我的c3p0数据库连接池依赖为:
解决方式:将依赖包改为
<!-- 数据库连接池 -->
<!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
总结
项目运行不起来,第一时间确实很慌,尤其是被大量看不懂的英文日志刷屏时,因此找准错误信息很重要,以我现在的经验来说,有两种方式:
- 从报错开始位置找
- 从报错结束位置找
然后仔细阅读并大胆猜测,推断报错原因