Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java liquibase与Spring Boot 2集成时出错_Java_Xml_Spring Boot_Yaml_Liquibase - Fatal编程技术网

Java liquibase与Spring Boot 2集成时出错

Java liquibase与Spring Boot 2集成时出错,java,xml,spring-boot,yaml,liquibase,Java,Xml,Spring Boot,Yaml,Liquibase,我正在从事一个Spring引导项目,我被要求使用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 ht

我正在从事一个Spring引导项目,我被要求使用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>

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

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

如果您没有经常使用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将为该变更集计算不同的校验和,并让您知道存在差异

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

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

  • 如果变更日志(或其引用的文件)发生错误更改,则要做的事情是将变更日志恢复到以前的状态。如果更改日志是通过编辑更改集(或更改文件,如
    sql/tables\u mysql.sql
    )更改的,这是不正确的-一旦更改集应用于任何数据库,对更改集正在更改的内容进行更改的正确方法是创建另一个更改集


  • 您没有指定文件
    sql/tables\u mysql.sql中的内容,但该文件的内容也用于校验和过程,因此,当这种情况发生变化时,您也会看到此错误。

    如果您没有太多地使用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将为该变更集计算不同的校验和,并让您知道存在差异

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

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

  • 如果变更日志(或其引用的文件)发生错误更改,则要做的事情是将变更日志恢复到以前的状态。如果更改日志是通过编辑更改集(或更改文件,如
    sql/tables\u mysql.sql
    )更改的,这是不正确的-一旦更改集应用于任何数据库,对更改集正在更改的内容进行更改的正确方法是创建另一个更改集


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

    要添加到@SteveDonie的答案中:

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

    • 7:18262C5C5851874DF0C954D60B47D59添加到变更集中
    • ANY
      添加到变更集中
    • 更改变更集的
      id
    • 正在删除
      databasechangelog
      表中有关此变更集的记录(我不建议这样做)
    • 删除数据库,然后从liquibase变更集重新创建它

    要添加到@SteveDonie的答案中:

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

    • 7:18262C5C5851874DF0C954D60B47D59添加到变更集中
    • ANY
      添加到变更集中
    • 更改变更集的
      id
    • 正在删除
      databasechangelog
      表中有关此变更集的记录(我不建议这样做)
    • 删除数据库,然后从liquibase变更集重新创建它

    请注意,上面的前4个选项都是解决办法,可能会让您克服障碍,但了解Liquibase在下面做什么很重要。如果添加一个
    validCheckSum
    属性,您将陷入这样一种情况:与产品关联的不同数据库(DEV vs TEST vs PROD)中可能包含不同的内容。如果您更改变更集的id,同样的事情-您已经将id=tableA的变更集部署到DEV,但是随后将id更改为tableA-1并部署到DEV-现在DEV已经部署了这两个变更集。部署到测试和测试只有表a-1。请注意,上面的前4个选项都是解决方法,可能会让您克服障碍,但了解Liquibase在下面做什么很重要。如果添加一个
    validCheckSum
    属性,您将陷入这样一种情况:与产品关联的不同数据库(DEV vs TEST vs PROD)中可能包含不同的内容。如果您更改变更集的id,同样的事情-您已经将id=tableA的变更集部署到DEV,但是随后将id更改为tableA-1并部署到DEV-现在DEV已经部署了这两个变更集。部署到测试,测试只有表A-1。