SpringBoot整合flyway實(shí)現(xiàn)自動(dòng)創(chuàng)建表的方法
spring boot - v: 2.1.3.RELEASE
MySQL - v:5.7
JDK -v : 11
項(xiàng)目結(jié)構(gòu):

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo-flywat</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo-flywat</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.yml
server:
port: 1234
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
password: root
url: jdbc:mysql://localhost:3306/demo?serverTimezone=UTC&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
flyway:
baseline-on-migrate: true
enabled: true
locations: classpath:/db/migration
必須在resource下新建這個(gè)名稱的文件夾,sql腳本的命名規(guī)則 : V${版本號(hào)}__${描述}.sql

啟動(dòng)后,不僅會(huì)把你腳本的表創(chuàng)建好,同時(shí)還會(huì)創(chuàng)建{flyway_schema_history}表,記錄的就是操作日志,之后初始化執(zhí)行一次

如果啟動(dòng)過(guò)程中,報(bào)錯(cuò) .idea中flyway-core.xml提示Message: 前言中不允許有內(nèi)容,修改一下即可

到此這篇關(guān)于SpringBoot整合flyway實(shí)現(xiàn)自動(dòng)創(chuàng)建表的文章就介紹到這了,更多相關(guān)SpringBoot整合flyway自動(dòng)創(chuàng)建表內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- SpringBoot整合Flyway的方法(數(shù)據(jù)庫(kù)版本遷移工具)
- Flyway詳解及Springboot集成Flyway的詳細(xì)教程
- SpringBoot整合flyway實(shí)現(xiàn)步驟解析
- SpringBoot使用flyway初始化數(shù)據(jù)庫(kù)
- SpringBoot項(xiàng)目集成Flyway詳細(xì)過(guò)程
- SpringBoot使用Flyway進(jìn)行數(shù)據(jù)庫(kù)管理的操作方法
- SpringBoot使用Flyway進(jìn)行數(shù)據(jù)庫(kù)遷移的實(shí)現(xiàn)示例
- springboot配置flyway(入門級(jí)別教程)
- spring boot整合flyway實(shí)現(xiàn)數(shù)據(jù)的動(dòng)態(tài)維護(hù)的示例代碼
相關(guān)文章
java redis 實(shí)現(xiàn)簡(jiǎn)單的用戶簽到功能
這篇文章主要介紹了java redis 實(shí)現(xiàn)簡(jiǎn)單的用戶簽到功能,幫助大家更好的理解和使用Java,感興趣的朋友可以了解下2020-12-12
淺談java調(diào)用Restful API接口的方式
這篇文章主要介紹了淺談java調(diào)用Restful API接口的方式,具有一定借鑒價(jià)值,需要的朋友可以參考下。2017-12-12
如何用Netty實(shí)現(xiàn)高效的HTTP服務(wù)器
這篇文章主要介紹了如何用Netty實(shí)現(xiàn)高效的HTTP服務(wù)器,對(duì)HTTP感興趣的同學(xué)可以參考一下2021-04-04
java實(shí)現(xiàn)數(shù)字轉(zhuǎn)換人民幣中文大寫工具
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)數(shù)字轉(zhuǎn)換人民幣中文大寫工具,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-04-04
Java異常--常見方法--自定義異常--增強(qiáng)try(try-with-resources)詳解
這篇文章主要介紹了Java異常--常見方法--自定義異常--增強(qiáng)try(try-with-resources)的相關(guān)知識(shí),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-03-03
如何使用mybatis-generator自動(dòng)生成代碼
這篇文章主要介紹了如何使用mybatis-generator自動(dòng)生成代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10
java讀取cvs文件并導(dǎo)入數(shù)據(jù)庫(kù)
這篇文章主要為大家詳細(xì)介紹了java讀取cvs文件并導(dǎo)入數(shù)據(jù)庫(kù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08

