简体   繁体   English

Liquibase无法为Spring Boot / MySQL应用执行

[英]Liquibase not executing for Spring Boot/MySQL app

Spring Boot 1.5.8 and Java 8 here. Spring Boot 1.5.8和Java 8在这里。 I've followed all the Spring Boot & Liquibase guides and I can't seem to get Liquibase to work. 我遵循了所有的Spring Boot&Liquibase指南,但似乎无法使Liquibase正常工作。

Here is a link to a GitHub repo for reproducing the issue exactly, but here's the scoop: 这里是GitHub存储库的链接,用于准确地再现问题,但这是独家新闻:

I have the following MySQL v8 database that gets created like so ahead of time (before the app runs): 我有以下这样的MySQL v8数据库,它是像这样提前创建的(在应用运行之前):

CREATE DATABASE IF NOT EXISTS troubleshooting_db CHARACTER SET utf8 COLLATE utf8_general_ci;

I have the following src/main/resources/db/changelog files: 我有以下src/main/resources/db/changelog文件:

db.changelog-master.yaml:
===
databaseChangeLog:
- include:
  file: db/changelog/1-setup.sql

1-setup.sql:
===
--liquibase formatted sql

--changeset troubleshooting:1 dbms:mysql
-- LOOKUPS
CREATE TABLE IF NOT EXISTS metric_range_categories (
    metric_range_category_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    metric_range_category_ref_id VARCHAR(36) NOT NULL,
    metric_range_category_name VARCHAR(250) NOT NULL,
    metric_range_category_label VARCHAR(250) NOT NULL,
    metric_range_category_description VARCHAR(500) NOT NULL,

    CONSTRAINT pk_metric_range_categories PRIMARY KEY (metric_range_category_id),

    INDEX idx_metric_range_categories_metric_range_category_ref_id (metric_range_category_ref_id),
    INDEX idx_metric_range_categories_metric_range_category_label (metric_range_category_label),

    CONSTRAINT uc_metric_range_categories_metric_range_category_ref_id UNIQUE (metric_range_category_ref_id),
    CONSTRAINT uc_metric_range_categories_metric_range_category_name UNIQUE (metric_range_category_name),
    CONSTRAINT uc_metric_range_categories_metric_range_category_label UNIQUE (metric_range_category_label)
);

-- Lots of other CREATE TABLE statements down here...

And the following JPA-annotated entity: 以及以下带有JPA注释的实体:

@Entity
@Table(name = "metric_range_categories")
@AttributeOverrides({
        @AttributeOverride(name = "id", column = @Column(name = "metric_range_category_id")),
        @AttributeOverride(name = "refId", column = @Column(name = "metric_range_category_ref_id")),
        @AttributeOverride(name = "name", column = @Column(name = "metric_range_category_name")),
        @AttributeOverride(name = "label", column = @Column(name = "metric_range_category_label")),
        @AttributeOverride(name = "description", column = @Column(name = "metric_range_category_description"))
})
public class MetricRangeCategory extends BaseLookup {
    public MetricRangeCategory() {
    }

    public MetricRangeCategory(Long id, String refId, String name, String label, String description) {
        super(id, refId, name, label, description);
    }
}

At runtime I get the following exception: 在运行时,出现以下异常:

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [metric_range_categories]
    at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:67)
    at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:50)
    at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:91)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:475)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
    ... 29 common frames omitted

So when it starts up, Liquibase does not excute/engage and so Hibernate JPA validation fails because its looking for a table that doesn't exist (because Liquibase never kicked in and did its job!). 因此,当它启动时,Liquibase 不会执行/执行 ,因此Hibernate JPA验证失败,因为它正在寻找不存在的表(因为Liquibase从未加入并完成了工作!)。 Any ideas as to where I'm going awry? 关于我要去哪里的任何想法? Why isn't Liquibase kicking in? 为什么Liquibase不起作用?

There are 2 different problems in the repo : 回购中有2个不同的问题:

  1. Wrong location of application.yml. application.yml的位置错误。 Move it from root to src/main/resources 将其从根目录移到src / main / resources
  2. Nested property in TroubleshootingConfig.Machine has null value, because of this bean "authInfo" is not created and context initialization fails. 故障排除Config.Machine中的嵌套属性具有空值,因为未创建此bean“ authInfo”并且上下文初始化失败。 Here is the reference on how Spring Boot Configuration Binding works. 这是有关Spring Boot配置绑定如何工作的参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM