繁体   English   中英

将 liquibase 与 Spring Boot 2 集成时出错

[英]Error on integration of liquibase with Spring Boot 2

我正在做一个 Spring Boot 项目,我被要求使用 liquibase 调用一个 sql 文件。

sql 文件包含用于 Spring Quartz 表配置的脚本。

这是 POM 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.sap.lsm</groupId>
   <artifactId>SAPLicencesAndSecurityManagement</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>war</packaging>
   <name>SAPLicencesAndSecurityManagement</name>
   <parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
         <version>2.0.1.RELEASE</version>
         <relativePath /> <!-- lookup parent from repository -->
   </parent>

   <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
         <java.version>1.8</java.version>
         <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
   </properties>

   <dependencies>

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>

                <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>*</artifactId>
            </exclusion>
                       <exclusion>
                              <groupId>org.apache.logging.log4j</groupId>
                              <artifactId>*</artifactId>
                       </exclusion>

                </exclusions>
         </dependency>
         <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>

                <exclusions>
                       <exclusion>
                              <groupId>org.slf4j</groupId>
                              <artifactId>*</artifactId>
                       </exclusion>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>*</artifactId>
            </exclusion>
                       <exclusion>
                              <groupId>org.apache.logging.log4j</groupId>
                              <artifactId>*</artifactId>
                       </exclusion>
                </exclusions>
         </dependency>

         <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
                <exclusions>
                       <exclusion>
                              <groupId>org.slf4j</groupId>
                              <artifactId>*</artifactId>
                       </exclusion>
                       <exclusion>
                              <groupId>ch.qos.logback</groupId>
                              <artifactId>*</artifactId>
                       </exclusion>
                       <exclusion>
                              <groupId>org.apache.logging.log4j</groupId>
                              <artifactId>*</artifactId>
                       </exclusion>
                </exclusions>
         </dependency>

         <dependency>
         <groupId>com.google.guava</groupId>
         <artifactId>guava</artifactId>
         <version>19.0</version>
         </dependency>

                <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency> 


        <!-- javax mail -->
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
          <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>*</artifactId>
            </exclusion>
                       <exclusion>
                              <groupId>org.apache.logging.log4j</groupId>
                              <artifactId>*</artifactId>
                       </exclusion>

                </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
          <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>*</artifactId>
            </exclusion>
                       <exclusion>
                              <groupId>org.apache.logging.log4j</groupId>
                              <artifactId>*</artifactId>
                       </exclusion>

                </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
          <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>*</artifactId>
            </exclusion>
                       <exclusion>
                              <groupId>org.apache.logging.log4j</groupId>
                              <artifactId>*</artifactId>
                       </exclusion>

                </exclusions>
    </dependency>

    <!-- Quartz framework -->
    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>2.2.1</version>
          <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>*</artifactId>
            </exclusion>
                       <exclusion>
                              <groupId>org.apache.logging.log4j</groupId>
                              <artifactId>*</artifactId>
                       </exclusion>

                </exclusions>
    </dependency>

    <dependency>
         <groupId>org.liquibase</groupId>
         <artifactId>liquibase-core</artifactId>
        <version>3.3.5</version>
          <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>

          </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <type>jar</type>
        <scope>compile</scope>
          <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>*</artifactId>
            </exclusion>
                       <exclusion>
                              <groupId>org.apache.logging.log4j</groupId>
                              <artifactId>*</artifactId>
                       </exclusion>

                </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>

   </dependencies>


   <build>
         <finalName>SAPLicencesAndSecurityManagement</finalName>
         <plugins>
                <plugin>
                       <groupId>com.sap.lsm</groupId>
                       <artifactId>SAPLicencesAndSecurityManagement</artifactId>
                       <version>0.0.1-SNAPSHOT</version>
                </plugin> 

         </plugins>
   </build>

sql 文件的调用是通过名为db.changelog-master的 yaml 文件db.changelog-master

[![db.changelog-master.yaml][1]][1]

在此处输入图片说明

当我运行服务器时,控制台显示如下错误:

15:44:36.602 [localhost-startStop-1] ERROR com.mysql.jdbc.log.StandardLogger - Mon Jun 11 15:44:36 WAT 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
15:44:36.968 [HikariPool-1 connection adder] ERROR com.mysql.jdbc.log.StandardLogger - Mon Jun 11 15:44:36 WAT 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
15:44:36.997 [HikariPool-1 connection adder] ERROR com.mysql.jdbc.log.StandardLogger - Mon Jun 11 15:44:36 WAT 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
15:44:37.008 [HikariPool-1 connection adder] ERROR com.mysql.jdbc.log.StandardLogger - Mon Jun 11 15:44:37 WAT 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
15:44:39.081 [localhost-startStop-1] ERROR org.springframework.boot.SpringApplication - Application run failed
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.ValidationFailedException: Validation Failed:
 1 change sets check sum
      classpath:/db/changelog/db.changelog-master.yaml::2::marouane is now: 7:18262c5c5851874dff0c954d60b47d59

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1702)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:155)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:135)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: liquibase.exception.ValidationFailedException: Validation Failed:
 1 change sets check sum
      classpath:/db/changelog/db.changelog-master.yaml::2::marouane is now: 7:18262c5c5851874dff0c954d60b47d59

at liquibase.changelog.DatabaseChangeLog.validate(DatabaseChangeLog.java:196)
at liquibase.Liquibase.update(Liquibase.java:196)
at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:415)
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:379)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1761)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1698)
... 27 common frames omitted

添加到@SteveDonie 的回答中:

您可以通过以下方式解决此错误:

  • <validCheckSum>7:18262c5c5851874dff0c954d60b47d59</validCheckSum>到您的<validCheckSum>7:18262c5c5851874dff0c954d60b47d59</validCheckSum>
  • <validCheckSum>ANY</validCheckSum>到您的<validCheckSum>ANY</validCheckSum>
  • 更改您的 changeSet 的id
  • databasechangelog表中删除有关此变更集的记录(我不推荐这样做)。
  • 删除您的数据库,然后从您的 liquibase 更改集重新创建它。

如果您没有经常使用 Liquibase,错误信息就不是很清楚。

这条信息:

15:44:39.081 [localhost-startStop-1] ERROR org.springframework.boot.SpringApplication - Application run failed
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.ValidationFailedException: Validation Failed:
 1 change sets check sum
      classpath:/db/changelog/db.changelog-master.yaml::2::marouane is now: 7:18262c5c5851874dff0c954d60b47d59

是关键错误。 当 Liquibase 将变更集应用于数据库时,它会在该时刻计算变更集的校验和,并将校验和保存到数据库的 DATABASECHANGELOG 表中。 如果有人随后更改了变更集,然后尝试使用 Liquibase 更新数据库,Liquibase 将为该变更集计算不同的校验和,并让您知道存在差异。

至少有两种方法可以“解决”这个问题。

  1. 如果您知道可以更改数据库(也许它是一个开发实例)并且您也知道存在的变更集是正确的,那么您可以删除数据库并从变更日志中重新创建它。

  2. 如果更改日志(或它所引用的文件)被错误更改,那么要做的就是将更改日志恢复到之前的状态。 如果更改日志是通过编辑变更集(或更改sql/tables_mysql.sql类的文件)更改的,那是不正确的 - 一旦将变更集应用于任何数据库,对变更集正在更改的任何内容进行更改的正确方法是创建另一个变更集。

您没有指定文件sql/tables_mysql.sql的内容,但该文件的内容也在校验和过程中使用,因此当更改时,您也会看到此错误。

暂无
暂无

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

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