springboot flyway 整合(不生效原因)
·
前言:
整合springboot 和 flyway 其实网上有很多,但是我在用时发现一个问题,有版本的限制,如果大家发现flyway 不生效,可以使用下我这种指定jar版本的例子。
原因:个人发现可能版本出现了问题
代码下载链接:https://download.csdn.net/download/wcy18818429914/19777008
1、POM 文件(更新下pom 就可以了)
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.8.RELEASE</version>
</dependency>
<!--flyway-->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>5.2.4</version>
</dependency>
<!--mysql连接依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.3</version>
</dependency>
</dependencies>
这里是顺便整合下springboot 和 flyway 的功能

V0.1.2__init_data.sql
drop table if exists id_name;
/*==============================================================*/
/* Table: sh_virtual_device */
/*==============================================================*/
create table id_name
(
id varchar(36) not null comment '主键',
name varchar(36) comment '名称',
primary key (id)
);
application.yml
server:
port: 8010
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/flyway?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true
username: root
password: root
sql-script-encoding: UTF-8 #指定插入数据库数据的编码方式
flyway:
baseline-on-migrate: true
运行DemoApplication程序
结果如下:

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)