簡體   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