如何为spring-boot和hibernate配置liquibase-maven-plugin

时间:2018-01-01 17:55:07

标签: java hibernate spring-boot liquibase liquibase-hibernate

我有非常典型的应用程序堆栈:spring-boot:1.5.Xhibernate:5.Xmavenliquibase

使用liquibase配置spring boot很简单,无需添加某些配置文件,尤其是liquibase

但我想通过liquibase changesets创建hibernate entities。我想我可以用liquibase-maven-pluginliquibase-hibernate来做到这一点。此外,我已阅读this article about integration spring boot and liquibase,但需要额外的liquibase.properties

我的问题是:如果可能的话,我怎样才能配置maven-liqubase插件而不添加一些配置文件。

1 个答案:

答案 0 :(得分:0)

我的配置是

         <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>${liquibase.version}</version>
            <configuration>
                <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
                <diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
                <driver>org.mariadb.jdbc.Driver</driver>
                <url>jdbc:mariadb://localhost:3306/example</url>
                <defaultSchemaName>example</defaultSchemaName>
                <username>root</username>
                <password>root</password>
                <referenceUrl>hibernate:spring:com.example.domain?dialect=org.hibernate.dialect.MySQL5Dialect&amp;hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&amp;hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl>
                <!-- <verbose>true</verbose> -->
                <!-- <logging>debug</logging> -->
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.liquibase.ext</groupId>
                    <artifactId>liquibase-hibernate5</artifactId>
                    <version>${liquibase-hibernate5.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-validator</artifactId>
                    <version>${hibernate-validator.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-data-jpa</artifactId>
                    <version>${project.parent.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                    <version>4.3.21.RELEASE</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                    <version>4.3.21.RELEASE</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                    <version>4.3.21.RELEASE</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework.data</groupId>
                    <artifactId>spring-data-jpa</artifactId>
                    <version>1.11.17.RELEASE</version>
                </dependency>
            </dependencies>
        </plugin>

这对任何mvn liquibase:命令都适用,除了mvn liquibase:diff会为我返回错误:[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.6.2:diff (default-cli) on project example: Error setting up or running Liquibase: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory: The application must supply JDBC connections