【问题标题】:Are spring-boot-starter-data-jpa and Liquibase incompatible?spring-boot-starter-data-jpa 和 Liquibase 不兼容吗?
【发布时间】:2021-06-12 22:15:50
【问题描述】:

我尝试设置一个新的 Spring Boot 2.4.3 项目,我想包括 Liquibase 以及 Spring Data JPA。 为了实现这一点,我在我的 POM 中使用了以下依赖项:

    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
        <version>${liquibase.version}</version>
    </dependency>
    or...
    <dependency>
        <groupId>org.liquibase.ext</groupId>
        <artifactId>liquibase-hibernate5</artifactId>
        <version>${liquibase.version}</version>
    </dependency>
    ...respectively and 
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <kotlin.version>1.4.31</kotlin.version>
    <liquibase.version>4.3.1</liquibase.version>
    <hibernate.version>5.4.29.Final</hibernate.version>

然而,一开始,到目前为止,我还没有任何数据库设置,在application.yaml 你可以找到:

server:
  port: 8080
spring:
  liquibase:
    change-log: classpath:db/changelog/db.changelog.yml

wherbey db.changelog.yml 是空的。

使用 spring-boot-starter-data-jpa 依赖项安装 Maven 会导致:

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is 
liquibase.exception.ChangeLogParseException: Empty file classpath:db/changelog/db.changelog.yml
Caused by: liquibase.exception.ChangeLogParseException: Empty file classpath:db/changelog/db.changelog.yml

当注释掉这个依赖时,构建成功。

【问题讨论】:

    标签: spring-boot hibernate spring-data-jpa liquibase


    【解决方案1】:

    我发现空的db.changelog.yml文件必须至少包含:

    databaseChangeLog:
      - changeset:
    

    虽然在https://docs.liquibase.com/concepts/basic/changelog.html 上给出了一个示例,一个空的changelog.yaml 文件需要看起来像:

    databaseChangeLog:
    

    ,但这会导致 BeanCreationException:

    Caused by: liquibase.exception.ChangeLogParseException: Could not find databaseChangeLog node
    

    【讨论】:

      猜你喜欢
      • 2017-11-29
      • 2021-11-11
      • 2021-01-18
      • 2021-02-09
      • 2018-08-06
      • 2018-03-01
      • 1970-01-01
      • 2016-11-12
      • 2015-10-13
      相关资源
      最近更新 更多