SpringBoot整合mybatis异常

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

springboot与mybatis整合需要注意几点

如果引入的是低版本的数据库连接驱动

<dependency>
	<groupId>mysqlgroupId>
	<artifactId>mysql-connector-javaartifactId>
	<version>5.1.47version> 
dependency>

<dependency>
	<groupId>org.springframework.bootgroupId>
	<artifactId>spring-boot-starter-jdbcartifactId>
dependency>


<dependency>
	<groupId>org.mybatis.spring.bootgroupId>
	<artifactId>mybatis-spring-boot-starterartifactId>
	<version>1.3.0version>
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
如果引入的是高版本的数据库连接驱动

<dependency>
	<groupId>mysqlgroupId>
	<artifactId>mysql-connector-javaartifactId>
dependency>


<dependency>
	<groupId>org.springframework.bootgroupId>
	<artifactId>spring-boot-starter-jdbcartifactId>
dependency>


<dependency>
	<groupId>org.mybatis.spring.bootgroupId>
	<artifactId>mybatis-spring-boot-starterartifactId>
	<version>1.3.0version>
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

如果不改动,当我们启动项目的时候并不会报错,但访问数据的时候页面就会出错:
SpringBoot整合mybatis异常_第1张图片
具体报错信息:

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.

你可能感兴趣的:(#,Springboot)