这期内容当中小编将会给大家带来有关liquibase怎么在SpringBoot中使用,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
<强>一、引入依赖强>
先在pom文件里引入依赖
& lt; dependency> ,& lt; groupId> org.liquibase ,& lt; artifactId> liquibase-core & lt;/dependency>
<强>二,指定配置文件位置强>
在代码中新建一个<代码> LiquibaseConfig> 代码类,用于配置<代码> Liquibase> 代码,指定配置文件的位置。
import javax.sql.DataSource; import liquibase.integration.spring.SpringLiquibase; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @ configuration public class  LiquibaseConfig { ,@ bean ,public SpringLiquibase  liquibase (DataSource 数据源),{ ,SpringLiquibase liquibase =, new SpringLiquibase (); ,liquibase.setDataSource(数据源); ,//指定的更新日志的位置,这里使用的一个主文件引用其他文件的方式 ,liquibase.setChangeLog(“类路径:liquibase/master.xml"); ,liquibase.setContexts(“开发、测试,production"); ,liquibase.setShouldRun(真正的); ,return liquibase; ,} }
<强>三、编写配置文件强>
目录结构:
& lt; databaseChangeLog xmlns=才能“http://www.liquibase.org/xml/ns/dbchangelog" ,,xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance" ,xsi: schemaLocation=癶ttp://www.liquibase.org/xml/ns/dbchangelog ,,,http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"的在 ,& lt; includeAll 路径=發iquibase/变更/?relativeToChangelogFile=癴alse"/比; & lt;/databaseChangeLog>
<代码> includeAll> 代码标签可以把一个文件夹下的所有的更新日志都加载进来。如果单个加载可以用<代码> 代码>。
<代码> includeAll> 代码标签里有两个属性:<代码>路径代码>和<代码> relativeToChangelogFile> 代码。
文件AttributeDescriptionfileName import requiredrelativeToChangelogFileIs文件路径相对于根目录的更新日志文件,而不是到类路径中。默认为“false",自1.9
<代码>路径> 代码(在包括标签里是文件):指定要加载的文件或文件夹位置
<代码> relativeToChangelogFile> 代码:文件位置的路径是否相对于根的更新日志是相对路径,默认假,即相对于类路径是相对路径。
<强>、强>
另在<代码> liquibase 代码>文件夹下新建<代码>、代码>文件夹用来存放changelog。
这里新建一个<代码>更新日志- 1.0。xml代码>
& lt; databaseChangeLog xmlns=才能“http://www.liquibase.org/xml/ns/dbchangelog" ,,xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance" ,xsi: schemaLocation=癶ttp://www.liquibase.org/xml/ns/dbchangelog ,,,http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"的在 ,& lt; changeSet id=?0190713 - 01 -“,作者=皊olo"比; & lt;才能createTable 表=皃roject_info"比; ,,& lt; column name=皃roject_id",类型=皏archar(64)“,编码=皍tf8",讲话=跋钅縤d"比; ,,,& lt; constraints primaryKey=皌rue", nullable=癴alse"/比; ,,& lt;/column> ,,& lt; column name=皃roject_name",类型=皏archar(255)“,编码=皍tf8",讲话=跋钅棵帧?比; ,,& lt; column name=皃roject_difficulty",类型=癴loat",编码=皍tf8",讲话=跋钅磕讯取?比; ,,& lt; column name=癱ategory_id",类型=皏archar(64)“,编码=皍tf8",讲话=跋钅坷嘈屠嗄勘嗪拧?比; ,,& lt; column name=皃roject_status",类型=癷nt(11)“,编码=皍tf8",讲话=跋钅孔刺?,0招募中,1,进行中,2已完成,3失败,4延期,5删除“/比; ,,& lt; column name=皃roject_desc",类型=皏archar(512)“,编码=皍tf8",讲话=跋钅考蚪椤?比; ,,& lt; column name=皃roject_creater_id",类型=皏archar(64)“,编码=皍tf8",讲话=跋钅看唇ㄕ遡d"/比; ,,& lt; column name=皌eam_id",类型=皏archar(64)“,编码=皍tf8",讲话=跋钅克敉哦觟d"/比; null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null nullliquibase怎么在SpringBoot中使用