SpringBoot整合mybatis异常

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection

springboot与mybatis整合需要注意几点

如果引入的是低版本的数据库连接驱动
<!--mysql驱动包-->
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>5.1.47</version> <!--低版本数据库连接驱动-->
</dependency>
<!--springboot与JDBC整合包-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<!--springboot与mybatis的整合包-->
<dependency>
	<groupId>org.mybatis.spring.boot</groupId>
	<artifactId>mybatis-spring-boot-starter</artifactId>
	<version>1.3.0</version>
</dependency>

application.properties配置如下:

#端口配置
server.port = 8080 

#数据库配置
spring.datasource.url = jdbc:mysql://localhost:3306/数据库名?useSSL=false
#用户名
spring.datasource.username = 
#密码
spring.datasource.password = 
#驱动
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
如果引入的是高版本的数据库连接驱动
<!--mysql驱动包-->
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId><!--不说明版本默认是最新的-->
</dependency>

<!--springboot与JDBC整合包-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<!--springboot与mybatis的整合包-->
<dependency>
	<groupId>org.mybatis.spring.boot</groupId>
	<artifactId>mybatis-spring-boot-starter</artifactId>
	<version>1.3.0</version>
</dependency>

application.properties配置需要修改一下,如下:

spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/数据库名?useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

如果不改动,当我们启动项目的时候并不会报错,但访问数据的时候页面就会出错:
在这里插入图片描述
具体报错信息:

There was an unexpected error (type=Internal Server Error, status=500).
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: The server time zone value '?????????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you
want to utilize time zone support. ### The error may exist in com/example/app/mapper/UserRepository.java (best guess) ### The error may involve com.example.app.mapper.UserRepository.
getAllUser ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: The server time zone value '?????????' is unrecognized or represents 
more than one time zone. You must configure either 
the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值