一、加入liquibase core jar包
maven ,gradle ,jar ……根据个人喜好
二、配置bean(xml配置或者@bean注释)
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="dataSource" ref="pvaDataSource"/>
<property name="changeLog" value="classpath:config/liquibase/master.xml"/>
<property name="contexts" value="test, production"/>
</bean>
master.xml文件(主要记录DB变更log,即databaseChangeLog)
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<include file="classpath:config/liquibase/changelog/20160918152401_add_entity_user.xml" relativeToChangelogFile="false"/>
</databaseChangeLog>
20160918152401_add_entity_user.xml文件(主要是table改变集合,即changeSet)
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<property name="now" value="now()" dbms="mysql,h2" />
<property name="now" value="current_timestamp" dbms="postgresql" />
<property name="now" value="sysdate" dbms="oracle" />
<changeSet id="20160918152401" author="WATER">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="user" />
</not>
</preConditions>
<createTable tableName="user">
<column name="id" type="varchar(120)">
<constraints nullable="false" />
</column>
<column name="name" type="varchar(200)">
<constraints nullable="false" />
</column>
</createTable>
</changeSet>
</databaseChangeLog>
总体结构图