记录几种异常的处理方法:
1、 Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext-dao.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy
原因是缺少spring-jdbc jar包
引入依赖或jar包即可
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>4.3.7.RELEASE</version> </dependency>
2、异常报错:An SQLException was provoked by the following failure: java.lang.InterruptedException
原因是没引入mysql-connector-java的jar包,或是mysql-connector-java的版本问题,升级至与mysql版本一致即可。
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.13</version> </dependency>
3、springMVC开发web的时候,报错:java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config
原因:未引入jstl包
pom.xml引入jstl,问题解决。
<!-- java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
4、在JDBC使用的时候有时候会出现java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents........的错误,具体错误如下:
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
出现这个的原因是因为 mysql返回的时间总是有问题,比实际时间要早8小时。
解决办法:
在url后面添加 serverTimezone=Asia/Shanghai :
jdbc.url=jdbc:mysql://127.0.0.1:3306/caipiao?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|