SpringBoot 集成数据库迁移工具 Flyway(基于Gradle构建)
------ 源代码:Github
由于在整合时用到了一些相关的数据库技术,就不一一详解了,具体如下:
- flyway plugin: org.flywaydb.flyway
- Druid: druid-spring-boot-starter
- JPA:spring-boot-starter-data-jpa
1. 引入插件和依赖(build.gradle)
plugins {
id 'java'
id "org.springframework.boot" version '2.1.2.RELEASE'
id "org.flywaydb.flyway" version "5.1.4" // Flyway 插件
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
// JPA
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// flyway
implementation "org.flywaydb:flyway-core:5.2.4"
// 数据库
implementation 'com.alibaba:druid-spring-boot-starter:1.1.10'
runtimeOnly 'mysql:mysql-connector-java:8.0.12'
}
2. 编写配置文件(application.yml)
spring:
flyway:
url: jdbc:mysql://127.0.0.1:3306/flyway_test?useUnicode=true&characterEncoding=utf8&am