Springboot整合mybatis+Mysql8+druid
Springboot整合mybatis+mysql8+druid
踩了⽆数坑,最重要的⼀点: 引⼊的依赖⼀定要正确啊
我踩过的那些坑
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
2.在application.properties配置⽂件中。应为这⾥使⽤了druid数据库连接池,在配置url,username等参数时,其前缀是
spring.datasource.druid
⽽不是
spring.datasource
3.在配置mysql的url的时候就照我的写吧,⼜时候你会因为时区(serverTimezone)啊,编码格式(characterEncoding)啊没配置导致连接数据库失败。(说多了都是泪啊)
spring.datasource.druid.url=jdbc:mysql://localhost:3306/learnjdbc?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=tr ue
4.因为使⽤的是Mysql8的版本,所以配置⽂件中driver-class-name是sql.cj.jdbc.Driver⽽不是sql.jdbc.Driver
依赖(l)
这⾥需要引⼊mybatis,mysql,druid的依赖(注意这⾥是针对Mysql8的版本)
<!--mysql依赖-->
<dependency>
<groupId>mysql</groupId>
druid连接池配置详解<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
<!--mybatis依赖-->
<dependency>
<groupId&batis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
<!--阿⾥系的Druid依赖包-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
配置⽂件(application.properties)
#配置数据源
spring.datasource.druid.url=jdbc:mysql://localhost:3306/learnjdbc?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=tr ue
spring.datasource.druid.username=root
spring.datasource.druid.password=**********
spring.datasource.druid.sql.cj.jdbc.Driver

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。